|
|
@@ -6,8 +6,9 @@ import (
|
|
|
|
|
|
// VPoint is an single server in V2Ray system.
|
|
|
type VPoint struct {
|
|
|
- config VConfig
|
|
|
- connHandler ConnectionHandler
|
|
|
+ config VConfig
|
|
|
+ ichFactory InboundConnectionHandlerFactory
|
|
|
+ ochFactory OutboundConnectionHandlerFactory
|
|
|
}
|
|
|
|
|
|
// NewVPoint returns a new VPoint server based on given configuration.
|
|
|
@@ -18,16 +19,32 @@ func NewVPoint(config *VConfig) (*VPoint, error) {
|
|
|
return vpoint, nil
|
|
|
}
|
|
|
|
|
|
-type ConnectionHandler interface {
|
|
|
+type InboundConnectionHandlerFactory interface {
|
|
|
+ Create(vPoint *VPoint) (InboundConnectionHandler, error)
|
|
|
+}
|
|
|
+
|
|
|
+type InboundConnectionHandler interface {
|
|
|
Listen(port uint16) error
|
|
|
}
|
|
|
|
|
|
+type OutboundConnectionHandlerFactory interface {
|
|
|
+ Create(vPoint *VPoint) (OutboundConnectionHandler, error)
|
|
|
+}
|
|
|
+
|
|
|
+type OutboundConnectionHandler interface {
|
|
|
+ Start(vray *OutboundVRay) 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)
|
|
|
+ inboundConnectionHandler, err := vp.ichFactory.Create(vp)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err = inboundConnectionHandler.Listen(vp.config.Port)
|
|
|
return nil
|
|
|
}
|