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
|
|
|
|
|
|
|
"v2ray.com/core/common"
|
|
|
|
)
|
2016-12-08 15:27:41 +00:00
|
|
|
|
|
|
|
type PacketHeader interface {
|
|
|
|
Size() int
|
2016-12-09 11:08:25 +00:00
|
|
|
Write([]byte) (int, error)
|
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
|
|
|
}
|