MCPcopy
hub / github.com/txthinking/brook / Exchange

Method Exchange

simplepacketclient.go:46–87  ·  view source on GitHub ↗
(local net.Conn)

Source from the content-addressed store, hash-verified

44}
45
46func (c *SimplePacketClient) Exchange(local net.Conn) error {
47 go func() {
48 for {
49 if c.Timeout != 0 {
50 if err := c.Server.SetDeadline(time.Now().Add(time.Duration(c.Timeout) * time.Second)); err != nil {
51 return
52 }
53 }
54 i, err := c.Server.Read(c.RB)
55 if err != nil {
56 return
57 }
58 _, h, _, err := socks5.ParseBytesAddress(c.RB[0:])
59 if err != nil {
60 Log(err)
61 return
62 }
63 _, err = local.Write(c.RB[1+len(h)+2 : i])
64 if err != nil {
65 return
66 }
67 }
68 }()
69 for {
70 if c.Timeout != 0 {
71 if err := local.SetDeadline(time.Now().Add(time.Duration(c.Timeout) * time.Second)); err != nil {
72 return nil
73 }
74 }
75 l, err := local.Read(c.WB[32+4+c.dstl:])
76 if err != nil {
77 return nil
78 }
79 copy(c.WB[0:32], c.Password)
80 binary.BigEndian.PutUint32(c.WB[32:32+4], uint32(time.Now().Unix()))
81 _, err = c.Server.Write(c.WB[:32+4+c.dstl+l])
82 if err != nil {
83 return nil
84 }
85 }
86 return nil
87}
88
89func (s *SimplePacketClient) Clean() {
90 x.BP65507.Put(s.RB)

Callers

nothing calls this directly

Calls 3

SetDeadlineMethod · 0.45
ReadMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected