// 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 }
func init() { gslogger.NewFlags(gslogger.ERROR | gslogger.INFO) var err error client, err = tcp.BuildClient(gorpc.BuildPipeline(eventLoop)).Connect("test") if err != nil { panic(err) } server = BindServer(0, client.Pipeline()) }
func main() { gslogger.NewFlags(gslogger.ERROR | gslogger.INFO) var eventLoop = gorpc.NewEventLoop(uint32(runtime.NumCPU()), 2048, 500*time.Millisecond) tcp.NewServer( gorpc.BuildPipeline(eventLoop), ).EvtNewPipeline(tcp.EvtNewPipeline(func(pipeline gorpc.Pipeline) { pipeline.AddService(rpctest.MakeServer(0, &_MockServer{})) })).Listen(":13512") }
// Connect func (system *_System) Connect(name string, raddr string) (gorpc.Client, error) { builder := gorpc.NewClientBuilder( name, gorpc.BuildPipeline(time.Millisecond*10).Handler( "profile", gorpc.ProfileHandler, ).Handler( "tunnel-client", func() gorpc.Handler { return system.newTunnelClient(raddr) }, ).Timeout(system.timeout), ) builder.Reconnect(system.timeout) return gorpc.TCPConnect(builder, name, raddr) }
return val, nil } return "", NewResourceError() } 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 {