Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
esrrhs committed Oct 22, 2019
1 parent f275f81 commit 13b2cbc
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 3 deletions.
1 change: 1 addition & 0 deletions gen.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
protoc --go_out=. *.proto
249 changes: 249 additions & 0 deletions msg.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions msg.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
syntax = "proto3";
option go_package = "pingtunnel";
message MyMsg {
string id = 1;
int32 type = 2;
string target = 3;
bytes data = 4;
int32 rproto = 5;
int32 catch = 6;
int32 key = 7;
int32 tcpmode = 8;
int32 tcpmode_buffersize = 9;
int32 tcpmode_maxwin = 10;
int32 tcpmode_resend_timems = 11;
}

message Frame {
int32 type = 1;
bool resend = 2;
int64 sendtime = 3;
int32 id = 4;
bytes data = 5;
repeated int32 dataid = 6;
}
3 changes: 1 addition & 2 deletions pingtunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const (
DATA uint32 = 0x01010101
PING uint32 = 0x02020202
CATCH uint32 = 0x03030303
FRAME uint32 = 0x04040404
END uint32 = 0xAAAABBBB
)

Expand Down Expand Up @@ -217,7 +216,7 @@ func recvICMP(conn icmp.PacketConn, recv chan<- *Packet) {
my := &MyMsg{}
my.Unmarshal(bytes[8:n])

if (my.TYPE != (uint32)(DATA) && my.TYPE != (uint32)(PING) && my.TYPE != (uint32)(CATCH) && my.TYPE != (uint32)(FRAME)) ||
if (my.TYPE != (uint32)(DATA) && my.TYPE != (uint32)(PING) && my.TYPE != (uint32)(CATCH)) ||
my.ENDTYPE != (uint32)(END) {
loggo.Info("processPacket diff type %s %d %d ", my.ID, my.TYPE, my.ENDTYPE)
continue
Expand Down
42 changes: 41 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,46 @@ func (p *Server) processPacket(packet *Packet) {
}
}

func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {

loggo.Info("server waiting target response %s -> %s %s", conn.tcpaddrTarget.String(), conn.id, conn.tcpconn.LocalAddr().String())

for {
bytes := make([]byte, 2000)

conn.conn.SetReadDeadline(time.Now().Add(time.Millisecond * 100))
n, _, err := conn.conn.ReadFromUDP(bytes)
if err != nil {
if neterr, ok := err.(*net.OpError); ok {
if neterr.Timeout() {
// Read timeout
continue
} else {
loggo.Error("ReadFromUDP Error read udp %s", err)
conn.close = true
return
}
}
}

now := time.Now()
conn.activeTime = now

if conn.catch > 0 {
select {
case conn.catchQueue <- &CatchMsg{conn: conn, id: id, src: src, data: bytes[:n]}:
case <-time.After(time.Duration(10) * time.Millisecond):
}
} else {
sendICMP(p.echoId, p.echoSeq, *p.conn, src, "", id, (uint32)(DATA), bytes[:n],
conn.rproto, -1, 0, p.key, 0)
}

p.sendPacket++
p.sendPacketSize += (uint64)(n)
}
}

func (p *Server) Recv(conn *ServerConn, id string, src *net.IPAddr) {

loggo.Info("server waiting target response %s -> %s %s", conn.ipaddrTarget.String(), conn.id, conn.conn.LocalAddr().String())
Expand Down Expand Up @@ -212,7 +252,7 @@ func (p *Server) Recv(conn *ServerConn, id string, src *net.IPAddr) {
}
} else {
sendICMP(p.echoId, p.echoSeq, *p.conn, src, "", id, (uint32)(DATA), bytes[:n],
conn.rproto, -1, 0, p.key, packet.tcpmode)
conn.rproto, -1, 0, p.key, 0)
}

p.sendPacket++
Expand Down

0 comments on commit 13b2cbc

Please sign in to comment.