github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/transport/internet/header.go (about) 1 package internet 2 3 import ( 4 "context" 5 "net" 6 7 "v2ray.com/core/common" 8 ) 9 10 type PacketHeader interface { 11 Size() int32 12 Serialize([]byte) 13 } 14 15 func CreatePacketHeader(config interface{}) (PacketHeader, error) { 16 header, err := common.CreateObject(context.Background(), config) 17 if err != nil { 18 return nil, err 19 } 20 if h, ok := header.(PacketHeader); ok { 21 return h, nil 22 } 23 return nil, newError("not a packet header") 24 } 25 26 type ConnectionAuthenticator interface { 27 Client(net.Conn) net.Conn 28 Server(net.Conn) net.Conn 29 } 30 31 func CreateConnectionAuthenticator(config interface{}) (ConnectionAuthenticator, error) { 32 auth, err := common.CreateObject(context.Background(), config) 33 if err != nil { 34 return nil, err 35 } 36 if a, ok := auth.(ConnectionAuthenticator); ok { 37 return a, nil 38 } 39 return nil, newError("not a ConnectionAuthenticator") 40 }