1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-20 06:25:24 +00:00
v2fly/transport/internet/header.go

41 lines
852 B
Go
Raw Normal View History

2016-12-08 15:27:41 +00:00
package internet
2017-01-12 21:47:10 +00:00
import (
"context"
2017-02-23 21:34:02 +00:00
"net"
2017-01-12 21:47:10 +00:00
"github.com/v2fly/v2ray-core/v5/common"
2017-01-12 21:47:10 +00:00
)
2016-12-08 15:27:41 +00:00
type PacketHeader interface {
2018-04-02 18:00:50 +00:00
Size() int32
2018-11-02 20:34:04 +00:00
Serialize([]byte)
2016-12-08 15:27:41 +00:00
}
2017-01-12 21:47:10 +00:00
func CreatePacketHeader(config interface{}) (PacketHeader, error) {
header, err := common.CreateObject(context.Background(), config)
if err != nil {
return nil, err
2016-12-08 15:27:41 +00:00
}
2017-02-23 21:34:02 +00:00
if h, ok := header.(PacketHeader); ok {
2017-01-12 21:47:10 +00:00
return h, nil
2016-12-08 15:27:41 +00:00
}
2017-04-09 13:04:04 +00:00
return nil, newError("not a packet header")
2017-02-23 21:34:02 +00:00
}
type ConnectionAuthenticator interface {
Client(net.Conn) net.Conn
Server(net.Conn) net.Conn
}
func CreateConnectionAuthenticator(config interface{}) (ConnectionAuthenticator, error) {
auth, err := common.CreateObject(context.Background(), config)
if err != nil {
return nil, err
}
if a, ok := auth.(ConnectionAuthenticator); ok {
return a, nil
}
2017-04-09 13:04:04 +00:00
return nil, newError("not a ConnectionAuthenticator")
2016-12-08 15:27:41 +00:00
}