2020-11-25 14:01:53 +03:00
|
|
|
package internet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
|
2020-12-04 04:36:16 +03:00
|
|
|
"github.com/xtls/xray-core/common"
|
2024-06-29 21:32:57 +03:00
|
|
|
"github.com/xtls/xray-core/common/errors"
|
2020-11-25 14:01:53 +03: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
|
|
|
|
}
|
2024-06-29 21:32:57 +03:00
|
|
|
return nil, errors.New("not a packet header")
|
2020-11-25 14:01:53 +03: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
|
|
|
|
}
|
2024-06-29 21:32:57 +03:00
|
|
|
return nil, errors.New("not a ConnectionAuthenticator")
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|