forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvpoint.go
33 lines (28 loc) · 781 Bytes
/
vpoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package core
import (
"fmt"
)
// VPoint is an single server in V2Ray system.
type VPoint struct {
config VConfig
connHandler ConnectionHandler
}
// NewVPoint returns a new VPoint server based on given configuration.
// The server is not started at this point.
func NewVPoint(config *VConfig) (*VPoint, error) {
var vpoint = new(VPoint)
vpoint.config = *config
return vpoint, nil
}
type ConnectionHandler interface {
Listen(port uint16) error
}
// Start starts the VPoint server, and return any error during the process.
// In the case of any errors, the state of the server is unpredicatable.
func (vp *VPoint) Start() error {
if vp.config.Port <= 0 {
return fmt.Errorf("Invalid port %d", vp.config.Port)
}
vp.connHandler.Listen(vp.config.Port)
return nil
}