P2p first version

This commit is contained in:
刘河
2019-02-26 22:40:28 +08:00
parent 204c53ddd3
commit 534d428c6d
23 changed files with 986 additions and 77 deletions

View File

@@ -13,12 +13,16 @@ const (
WORK_SEND_STATUS = "sdst"
WORK_CONFIG = "conf"
WORK_REGISTER = "rgst"
WORD_SECRET = "sert"
WORK_SECRET = "sert"
WORK_P2P = "p2pm"
WORK_P2P_VISITOR = "p2pv"
WORK_P2P_PROVIDER = "p2pp"
WORK_STATUS = "stus"
RES_SIGN = "sign"
RES_MSG = "msg0"
RES_CLOSE = "clse"
NEW_CONN = "conn" //新连接标志
NEW_UDP_CONN = "udpc" //p2p udp conn
NEW_TASK = "task" //新连接标志
NEW_CONF = "conf" //新连接标志
NEW_HOST = "host" //新连接标志
@@ -33,4 +37,5 @@ WWW-Authenticate: Basic realm="easyProxy"
ConnectionFailBytes = `HTTP/1.1 404 Not Found
`
)

View File

@@ -251,7 +251,29 @@ func GetIpByAddr(addr string) string {
func CopyBuffer(dst io.Writer, src io.Reader) (written int64, err error) {
buf := pool.BufPoolCopy.Get().([]byte)
io.CopyBuffer(dst, src, buf)
pool.PutBufPoolCopy(buf)
for {
nr, er := src.Read(buf)
if nr > 0 {
nw, ew := dst.Write(buf[0:nr])
if nw > 0 {
written += int64(nw)
}
if ew != nil {
err = ew
break
}
if nr != nw {
err = io.ErrShortWrite
break
}
}
if er != nil {
if er != io.EOF {
err = er
}
break
}
}
defer pool.PutBufPoolCopy(buf)
return written, err
}