void onAccepted(SelectionKey key, Context context) { TcpTunnel localTunnel = null; try { var localChannel = mServerSocketChannel.Accept(); localTunnel = TunnelFactory.wrap(localChannel, mSelector); short portKey = (short)localChannel.Socket().Port; var destAddress = getDestAddress(localChannel); if (destAddress != null) { TcpTunnel remoteTunnel = TunnelFactory.createTunnelByConfig(destAddress, mSelector, portKey, context); remoteTunnel.isHttpsRequest = localTunnel.isHttpsRequest; remoteTunnel.setBrotherTunnel(localTunnel); localTunnel.setBrotherTunnel(remoteTunnel); remoteTunnel.connect(destAddress); } } catch (Exception ex) { Debug.Fail($"TcpProxyServer onAccepted catch an exception: {ex}"); if (localTunnel != null) { localTunnel.dispose(); } } }
public static TunnelFactory WithPrioritySupport(this TunnelFactory factory) { if (factory is PriorityTunnelFactory) { return(factory); } return(new PriorityTunnelFactory()); }
/// <summary> /// Call this method to register a dependency resolver and set default TunnelFactory to DependencyInjectionTunnelFactory /// </summary> /// <param name="factory"></param> /// <param name="burrowResolver"></param> public static void RegisterResolver(this TunnelFactory factory, IBurrowResolver burrowResolver) { new DependencyInjectionTunnelFactory(burrowResolver); if (burrowResolver.Resolve <ITypeNameSerializer>() != null) { Global.DefaultTypeNameSerializer = burrowResolver.Resolve <ITypeNameSerializer>(); } }