2020-11-25 19:01:53 +08:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
|
|
import (
|
2020-12-04 09:36:16 +08:00
|
|
|
"github.com/xtls/xray-core/common/net"
|
2020-11-25 19:01:53 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ServerSpec struct {
|
2025-09-15 21:31:27 +08:00
|
|
|
Destination net.Destination
|
|
|
|
|
User *MemoryUser
|
2020-11-25 19:01:53 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-15 21:31:27 +08:00
|
|
|
func NewServerSpec(dest net.Destination, user *MemoryUser) *ServerSpec {
|
2020-11-25 19:01:53 +08:00
|
|
|
return &ServerSpec{
|
2025-09-15 21:31:27 +08:00
|
|
|
Destination: dest,
|
|
|
|
|
User: user,
|
2020-11-25 19:01:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewServerSpecFromPB(spec *ServerEndpoint) (*ServerSpec, error) {
|
|
|
|
|
dest := net.TCPDestination(spec.Address.AsAddress(), net.Port(spec.Port))
|
2025-09-15 21:31:27 +08:00
|
|
|
var dUser *MemoryUser
|
|
|
|
|
if spec.User != nil {
|
|
|
|
|
user, err := spec.User.ToMemoryUser()
|
2020-11-25 19:01:53 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2025-09-15 21:31:27 +08:00
|
|
|
dUser = user
|
2020-11-25 19:01:53 +08:00
|
|
|
}
|
2025-09-15 21:31:27 +08:00
|
|
|
return NewServerSpec(dest, dUser), nil
|
2020-11-25 19:01:53 +08:00
|
|
|
}
|