diff --git a/core.go b/core.go new file mode 100644 index 000000000..9ad48eaed --- /dev/null +++ b/core.go @@ -0,0 +1,2 @@ +// Package core provides common definitions and functionalities of V2Ray. +package core diff --git a/io/vmessreader.go b/io/vmessreader.go index 74ab0c2fa..5a7744c17 100644 --- a/io/vmessreader.go +++ b/io/vmessreader.go @@ -4,6 +4,7 @@ import ( "net" ) +// VMessInput implements the input message of VMess protocol. type VMessInput struct { version byte userHash [16]byte diff --git a/vconfig.go b/vconfig.go index 29ff3b284..6d3bac66f 100644 --- a/vconfig.go +++ b/vconfig.go @@ -1,14 +1,27 @@ package core +// User account that is used for connection to a VPoint type VUser struct { + // The ID of this VUser. This ID is served as an access token. + // It is not necessary to be permanent. id VID } +// The next VPoint server in the connection chain. +type VNext struct { + // Address of VNext server, in the form of "IP:Port" + ServerAddress string + // User accounts for accessing VNext. + User []VUser +} + +// The config for VPoint server. type VConfig struct { - RunAs VUser - Port uint16 - AllowedClients []VUser - AllowedProtocol string + // Port of this VPoint server. + Port uint16 + AllowedClients []VUser + ClientProtocol string + VNextList []VNext } type VConfigMarshaller interface { diff --git a/vid.go b/vid.go index d82b422af..29ca2042d 100644 --- a/vid.go +++ b/vid.go @@ -5,6 +5,7 @@ import ( "fmt" ) +// The ID of en entity, in the form of an UUID. type VID [16]byte var byteGroups = []int{8, 4, 4, 4, 12} diff --git a/vpoint.go b/vpoint.go index b0b0f94d7..b0c97c02c 100644 --- a/vpoint.go +++ b/vpoint.go @@ -9,8 +9,11 @@ type VPoint struct { 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 *VPoint + var vpoint = new(VPoint) + vpoint.config = *config return vpoint, nil } @@ -18,6 +21,8 @@ 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)