massive refactoring for interoperability

This commit is contained in:
Darien Raymond committed 2018-01-10 12:22:37 +01:00
1 parent 5a3c7fdd20
commit 292d7cc353
66 files changed
+1515 -1200

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
package router
import (
"context"
"v2ray.com/core/common/net"
"v2ray.com/core/transport/ray"
)
type Dispatcher interface {
Dispatch(ctx context.Context, dest net.Destination) (ray.InboundRay, error)
}
+53
View File
@@ -0,0 +1,53 @@
package router
import (
"context"
"sync"
)
type Router interface {
Pick(ctx context.Context) (string, bool)
}
type defaultRouter byte
func (defaultRouter) Pick(ctx context.Context) (string, bool) {
return "", false
}
type syncRouter struct {
sync.RWMutex
Router
}
func (r *syncRouter) Pick(ctx context.Context) (string, bool) {
r.RLock()
defer r.RUnlock()
return r.Router.Pick(ctx)
}
func (r *syncRouter) Set(router Router) {
r.Lock()
defer r.Unlock()
r.Router = router
}
var (
routerInstance = &syncRouter{
Router: defaultRouter(0),
}
)
func RegisterRouter(router Router) {
if router == nil {
panic("Router is nil.")
}
routerInstance.Set(router)
}
func Pick(ctx context.Context) (string, bool) {
return routerInstance.Router.Pick(ctx)
}