public I2PSession(int samPort, int?listenPort = null) { SamPort = samPort; ListenPort = listenPort; sessionId = new Random().Next(); controlSocket = new I2PSamConnection(SamPort); }
public async Task <Stream> ConnectAsync(string remoteDestination) { var connectionStream = new I2PSamConnection(SamPort); await connectionStream.Connect(); await connectionStream.SendCommand($"STREAM CONNECT ID={sessionId} DESTINATION={remoteDestination}"); return(connectionStream.GetStream()); }
public async Task ListenForIncomingConnectionsAsync() { if (isListeningForIncomingConnections) { throw new InvalidOperationException("Already listening for incoming connections."); } if (!ListenPort.HasValue) { throw new InvalidOperationException("No listen port specified."); } var listener = new TcpListener(IPAddress.Loopback, ListenPort.Value); isListeningForIncomingConnections = true; listener.Start(); var streamForwarder = new I2PSamConnection(SamPort); await streamForwarder.Connect(); await streamForwarder.SendCommand($"STREAM FORWARD ID={sessionId} PORT={ListenPort}"); ListenForConnections(listener); }