Пример #1
0
// Build .
func (builder *ProxyBuilder) Build(name string) Context {

	proxy := &_Proxy{
		Log:     gslogger.Get("gsproxy"),
		proxy:   builder.proxy,
		clients: make(map[string]*_Client),
		name:    name,
		tunnels: make(map[byte]byte),
	}

	proxy.frontend = gorpc.NewAcceptor(
		fmt.Sprintf("%s.frontend", name),
		gorpc.BuildPipeline(time.Millisecond*10).Handler(
			"gsproxy-profile",
			gorpc.ProfileHandler,
		).Handler(
			"gsproxy-hb",
			func() gorpc.Handler {
				return handler.NewHeartbeatHandler(builder.timeout)
			},
		).Handler(
			"gsproxy-dh",
			func() gorpc.Handler {
				return handler.NewCryptoServer(builder.dhkeyResolver)
			},
		).Handler(
			transProxyHandler,
			proxy.newTransProxyHandler,
		).Handler(
			"gsproxy-client",
			proxy.newClientHandler,
		),
	)

	proxy.backend = gorpc.NewAcceptor(
		fmt.Sprintf("%s.backend", name),
		gorpc.BuildPipeline(time.Millisecond*10).Handler(
			tunnelHandler,
			proxy.newTunnelServer,
		),
	)

	go func() {
		if err := gorpc.TCPListen(proxy.backend, builder.laddrE); err != nil {
			proxy.E("start agent backend error :%s", err)
		}
	}()

	go func() {
		if err := gorpc.TCPListen(proxy.frontend, builder.laddrF); err != nil {
			proxy.E("start agent frontend error :%s", err)
		}
	}()

	return proxy
}
Пример #2
0
}

var stateHandler = handler.NewStateHandler(func(pipeline gorpc.Pipeline, state gorpc.State) {

	pipeline.AddService(MakeRESTfull(1, &_MockRESTful{
		kv: make(map[string]string),
	}))

})

var acceptpor = gorpc.NewAcceptor("test-server",
	gorpc.BuildPipeline(time.Millisecond*10).Handler(
		"dh-server",
		func() gorpc.Handler {
			return handler.NewCryptoServer(handler.DHKeyResolve(func(device *gorpc.Device) (*handler.DHKey, error) {
				return handler.NewDHKey(G, P), nil
			}))
		},
	).Handler(
		"heatbeat-server",
		func() gorpc.Handler {
			return handler.NewHeartbeatHandler(5 * time.Second)
		},
	).Handler(
		"state-handler",

		func() gorpc.Handler {
			return stateHandler
		},
	),
)