MCPcopy Index your code
hub / github.com/txthinking/brook / Handle

Method Handle

simplepacketserverconn.go:40–72  ·  view source on GitHub ↗
(addr *net.UDPAddr, b, p []byte, w func([]byte) (int, error), timeout int)

Source from the content-addressed store, hash-verified

38}
39
40func (f *SimplePacketServerConnFactory) Handle(addr *net.UDPAddr, b, p []byte, w func([]byte) (int, error), timeout int) (net.Conn, []byte, error) {
41 if len(b) < 32+4 {
42 return nil, nil, errors.New("data too small")
43 }
44 if bytes.Compare(p, b[:32]) != 0 {
45 return nil, nil, errors.New("Password is wrong")
46 }
47 i := int64(binary.BigEndian.Uint32(b[32 : 32+4]))
48 if time.Now().Unix()-i > 60 {
49 return nil, nil, errors.New("Expired request")
50 }
51 a, h, p, err := socks5.ParseBytesAddress(b[32+4:])
52 if err != nil {
53 return nil, nil, err
54 }
55 dst := socks5.ToAddress(a, h, p)
56 f.Lock.Lock()
57 c, ok := f.Conns[addr.String()+dst]
58 f.Lock.Unlock()
59 if ok {
60 _ = c.In(b[32+4+1+len(h)+2:])
61 return nil, nil, nil
62 }
63 f.Lock.Lock()
64 c = NewPacketConn(b[32+4+1+len(h)+2:], w, timeout, func() {
65 f.Lock.Lock()
66 delete(f.Conns, addr.String()+dst)
67 f.Lock.Unlock()
68 })
69 f.Conns[addr.String()+dst] = c
70 f.Lock.Unlock()
71 return c, b[32+4 : 32+4+1+len(h)+2], nil
72}

Callers

nothing calls this directly

Calls 2

NewPacketConnFunction · 0.85
InMethod · 0.80

Tested by

no test coverage detected