func (this *TestPacketDispatcher) DispatchToOutbound(packet v2net.Packet) ray.InboundRay { traffic := ray.NewRay() this.LastPacket <- packet go this.Handler(packet, traffic) return traffic }
func (this *TestPacketDispatcher) DispatchToOutbound(destination v2net.Destination) ray.InboundRay { traffic := ray.NewRay() this.Destination <- destination go this.Handler(destination, traffic) return traffic }
func TestSinglePacket(t *testing.T) { v2testing.Current(t) port := v2nettesting.PickPort() tcpServer := &tcp.Server{ Port: port, MsgProcessor: func(data []byte) []byte { buffer := make([]byte, 0, 2048) buffer = append(buffer, []byte("Processed: ")...) buffer = append(buffer, data...) return buffer }, } _, err := tcpServer.Start() assert.Error(err).IsNil() freedom := &FreedomConnection{} traffic := ray.NewRay() data2Send := "Data to be sent to remote" payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send)) packet := v2net.NewPacket(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), port), payload, false) err = freedom.Dispatch(packet, traffic) assert.Error(err).IsNil() close(traffic.InboundInput()) respPayload := <-traffic.InboundOutput() defer respPayload.Release() assert.Bytes(respPayload.Value).Equals([]byte("Processed: Data to be sent to remote")) _, open := <-traffic.InboundOutput() assert.Bool(open).IsFalse() tcpServer.Close() }
func TestUnreachableDestination(t *testing.T) { v2testing.Current(t) freedom := &FreedomConnection{} traffic := ray.NewRay() data2Send := "Data to be sent to remote" payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send)) packet := v2net.NewPacket(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 128), payload, false) err := freedom.Dispatch(packet, traffic) assert.Error(err).IsNotNil() _, open := <-traffic.InboundOutput() assert.Bool(open).IsFalse() }
// Dispatches a Packet to an OutboundConnection. // The packet will be passed through the router (if configured), and then sent to an outbound // connection with matching tag. func (this *Point) DispatchToOutbound(context app.Context, packet v2net.Packet) ray.InboundRay { direct := ray.NewRay() dest := packet.Destination() dispatcher := this.och if this.router != nil { if tag, err := this.router.TakeDetour(dest); err == nil { if handler, found := this.odh[tag]; found { dispatcher = handler } } } go this.FilterPacketAndDispatch(packet, direct, dispatcher) return direct }
func (this *Point) DispatchToOutbound(packet v2net.Packet) ray.InboundRay { direct := ray.NewRay() dest := packet.Destination() if this.router != nil { tag, err := this.router.TakeDetour(dest) if err == nil { handler, found := this.odh[tag] if found { go handler.Dispatch(packet, direct) return direct } } } go this.och.Dispatch(packet, direct) return direct }
func TestUnreachableDestination(t *testing.T) { assert := assert.On(t) freedom := NewFreedomConnection( &Config{}, app.NewSpace(), &proxy.OutboundHandlerMeta{ Address: v2net.AnyIP, StreamSettings: &internet.StreamSettings{ Type: internet.StreamConnectionTypeRawTCP, }, }) traffic := ray.NewRay() data2Send := "Data to be sent to remote" payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send)) err := freedom.Dispatch(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 128), payload, traffic) assert.Error(err).IsNotNil() }
// Dispatches a Packet to an OutboundConnection. // The packet will be passed through the router (if configured), and then sent to an outbound // connection with matching tag. func (this *Point) DispatchToOutbound(context app.Context, packet v2net.Packet) ray.InboundRay { direct := ray.NewRay() dest := packet.Destination() dispatcher := this.och if this.router != nil { if tag, err := this.router.TakeDetour(dest); err == nil { if handler, found := this.odh[tag]; found { log.Info("Point: Taking detour [", tag, "] for [", dest, "]", tag, dest) dispatcher = handler } else { log.Warning("Point: Unable to find routing destination: ", tag) } } } go this.FilterPacketAndDispatch(packet, direct, dispatcher) return direct }
func TestSinglePacket(t *testing.T) { assert := assert.On(t) port := v2nettesting.PickPort() tcpServer := &tcp.Server{ Port: port, MsgProcessor: func(data []byte) []byte { buffer := make([]byte, 0, 2048) buffer = append(buffer, []byte("Processed: ")...) buffer = append(buffer, data...) return buffer }, } _, err := tcpServer.Start() assert.Error(err).IsNil() space := app.NewSpace() freedom := NewFreedomConnection( &Config{}, space, &proxy.OutboundHandlerMeta{ Address: v2net.AnyIP, StreamSettings: &internet.StreamSettings{ Type: internet.StreamConnectionTypeRawTCP, }, }) space.Initialize() traffic := ray.NewRay() data2Send := "Data to be sent to remote" payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send)) go freedom.Dispatch(v2net.TCPDestination(v2net.LocalHostIP, port), payload, traffic) traffic.InboundInput().Close() respPayload, err := traffic.InboundOutput().Read() assert.Error(err).IsNil() assert.Bytes(respPayload.Value).Equals([]byte("Processed: Data to be sent to remote")) tcpServer.Close() }
func (this *DefaultDispatcher) DispatchToOutbound(destination v2net.Destination) ray.InboundRay { direct := ray.NewRay() dispatcher := this.ohm.GetDefaultHandler() if this.router != nil { if tag, err := this.router.TakeDetour(destination); err == nil { if handler := this.ohm.GetHandler(tag); handler != nil { log.Info("DefaultDispatcher: Taking detour [", tag, "] for [", destination, "].") dispatcher = handler } else { log.Warning("DefaultDispatcher: Nonexisting tag: ", tag) } } else { log.Info("DefaultDispatcher: Default route for ", destination) } } go this.FilterPacketAndDispatch(destination, direct, dispatcher) return direct }
func (p *Point) DispatchToOutbound(packet v2net.Packet) ray.InboundRay { direct := ray.NewRay() go p.och.Dispatch(packet, direct) return direct }