Merge branch 'master' of https://github.com/esrrhs/pingtunnel
This commit is contained in:
commit
da7cbc2ef8
3 files changed
+39
-13
No files matched your search
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewClient(addr string, server string, target string, timeout int, sproto int, rproto int, catch int) (*Client, error) {
|
||||
func NewClient(addr string, server string, target string, timeout int, sproto int, rproto int, catch int, key int) (*Client, error) {
|
||||
|
||||
ipaddr, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
@@ -33,6 +33,7 @@ func NewClient(addr string, server string, target string, timeout int, sproto in
|
||||
sproto: sproto,
|
||||
rproto: rproto,
|
||||
catch: catch,
|
||||
key: key,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -44,6 +45,7 @@ type Client struct {
|
||||
sproto int
|
||||
rproto int
|
||||
catch int
|
||||
key int
|
||||
|
||||
ipaddr *net.UDPAddr
|
||||
addr string
|
||||
@@ -180,7 +182,8 @@ func (p *Client) Accept() error {
|
||||
}
|
||||
|
||||
clientConn.activeTime = now
|
||||
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, clientConn.id, (uint32)(DATA), bytes[:n], p.sproto, p.rproto, p.catch)
|
||||
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, clientConn.id, (uint32)(DATA), bytes[:n],
|
||||
p.sproto, p.rproto, p.catch, p.key)
|
||||
|
||||
p.sequence++
|
||||
|
||||
@@ -195,6 +198,10 @@ func (p *Client) processPacket(packet *Packet) {
|
||||
return
|
||||
}
|
||||
|
||||
if packet.key != p.key {
|
||||
return
|
||||
}
|
||||
|
||||
if packet.msgType == PING {
|
||||
t := time.Time{}
|
||||
t.UnmarshalBinary(packet.data)
|
||||
@@ -259,7 +266,8 @@ func (p *Client) ping() {
|
||||
if p.sendPacket == 0 {
|
||||
now := time.Now()
|
||||
b, _ := now.MarshalBinary()
|
||||
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto, p.catch)
|
||||
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b,
|
||||
p.sproto, p.rproto, p.catch, p.key)
|
||||
fmt.Printf("ping %s %s %d %d %d %d\n", p.addrServer, now.String(), p.sproto, p.rproto, p.id, p.sequence)
|
||||
p.sequence++
|
||||
}
|
||||
@@ -279,7 +287,8 @@ func (p *Client) showNet() {
|
||||
func (p *Client) sendCatch() {
|
||||
if p.catch > 0 {
|
||||
for _, conn := range p.localIdToConnMap {
|
||||
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, conn.id, (uint32)(CATCH), make([]byte, 0), p.sproto, p.rproto, p.catch)
|
||||
sendICMP(p.id, p.sequence, *p.conn, p.ipaddrServer, p.targetAddr, conn.id, (uint32)(CATCH), make([]byte, 0),
|
||||
p.sproto, p.rproto, p.catch, p.key)
|
||||
p.sequence++
|
||||
p.sendCatchPacket++
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user