vpoint.go 781 B

123456789101112131415161718192021222324252627282930313233
  1. package core
  2. import (
  3. "fmt"
  4. )
  5. // VPoint is an single server in V2Ray system.
  6. type VPoint struct {
  7. config VConfig
  8. connHandler ConnectionHandler
  9. }
  10. // NewVPoint returns a new VPoint server based on given configuration.
  11. // The server is not started at this point.
  12. func NewVPoint(config *VConfig) (*VPoint, error) {
  13. var vpoint = new(VPoint)
  14. vpoint.config = *config
  15. return vpoint, nil
  16. }
  17. type ConnectionHandler interface {
  18. Listen(port uint16) error
  19. }
  20. // Start starts the VPoint server, and return any error during the process.
  21. // In the case of any errors, the state of the server is unpredicatable.
  22. func (vp *VPoint) Start() error {
  23. if vp.config.Port <= 0 {
  24. return fmt.Errorf("Invalid port %d", vp.config.Port)
  25. }
  26. vp.connHandler.Listen(vp.config.Port)
  27. return nil
  28. }