Xray-core/transport/internet/header.go

42 lines
894 B
Go
Raw Normal View History

2020-11-25 11:01:53 +00:00
package internet
import (
"context"
"net"
2020-12-04 01:36:16 +00:00
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors"
2020-11-25 11:01:53 +00:00
)
type PacketHeader interface {
Size() int32
Serialize([]byte)
}
func CreatePacketHeader(config interface{}) (PacketHeader, error) {
header, err := common.CreateObject(context.Background(), config)
if err != nil {
return nil, err
}
if h, ok := header.(PacketHeader); ok {
return h, nil
}
return nil, errors.New("not a packet header")
2020-11-25 11:01:53 +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
}
return nil, errors.New("not a ConnectionAuthenticator")
2020-11-25 11:01:53 +00:00
}