Esempio n. 1
0
 internal void ReportRelayResponse(SSUHeader header, RelayResponse response, IPEndPoint ep)
 {
     if (RelayResponseReceived != null)
     {
         lock ( RelayResponseReceivedLock )
         {
             RelayResponseReceived(header, response, ep);
         }
     }
 }
Esempio n. 2
0
        public override SSUState HandleMessage(SSUHeader header, BufRefLen reader)
        {
#if LOG_ALL_TRANSPORT
            Logging.LogTransport($"SSU RelayRequestState: {Session.DebugId} Received {header.MessageType}");
#endif

            if (header.MessageType == SSUHeader.MessageTypes.RelayResponse)
            {
                var response = new RelayResponse(reader);
                return(HandleRelayResponse(response));
            }

            return(this);
        }
Esempio n. 3
0
        public override SSUState HandleMessage(SSUHeader header, BufRefLen reader)
        {
            switch (header.MessageType)
            {
            case SSUHeader.MessageTypes.SessionRequest:
                var req = new SessionRequest(reader, I2PPublicKey.DefaultAsymetricKeyCert);
                DebugUtils.Log("SSU SessionCreatedState " + Session.DebugId + " : OK SessionRequest received.");

                BufUtils.DHI2PToSessionAndMAC(out Session.SharedKey, out Session.MACKey,
                                              req.XKey.ModPow(PrivateKey.ToBigInteger(), I2PConstants.ElGamalP));

                Session.Host.ReportedAddress(new IPAddress(req.Address.ToByteArray()));

                // TODO: Remove comment when relaying is implemented

                /*
                 * if ( header.ExtendedOptions != null )
                 * {
                 *  if ( header.ExtendedOptions.Length == 2 && ( ( header.ExtendedOptions[0] & 0x01 ) != 0 ) )
                 *  {
                 *      RelayTag = BufUtils.RandomUint();
                 *  }
                 * }*/

                Request = req;
                SendSessionCreated();

                return(this);

            case SSUHeader.MessageTypes.RelayResponse:
                DebugUtils.LogDebug(() => string.Format("SSU SessionCreatedState {0}: RelayResponse received from {1}.",
                                                        Session.DebugId, (Session.RemoteEP == null ? "<null>" : Session.RemoteEP.ToString())));
                var response = new RelayResponse(reader);
                Session.Host.ReportRelayResponse(header, response, Session.RemoteEP);
                break;

            case SSUHeader.MessageTypes.SessionConfirmed:
                return(ParseSessionConfirmed(header, reader));

            case SSUHeader.MessageTypes.PeerTest:
                HandleIncomingPeerTestPackage(reader);
                break;

            default:
                DebugUtils.Log("SSU SessionCreatedState: Session " + Session.DebugId + " Unexpected Message: " + header.MessageType.ToString());
                break;
            }

            return(this);
        }
Esempio n. 4
0
 void Host_RelayResponseReceived(SSUHeader header, RelayResponse response, IPEndPoint ep)
 {
     if (header.MessageType == SSUHeader.MessageTypes.RelayResponse)
     {
         if (ep.Address.Equals(CurrentIntroducer.EndPoint.Address))
         {
             HandleRelayResponse(response);
         }
         else
         {
             Logging.LogTransport(
                 $"SSU RelayRequestState: {Session.DebugId} RelayResponse from {ep.Address} received. Waiting for response from {CurrentIntroducer.EndPoint.Address}.");
         }
     }
 }
Esempio n. 5
0
        SSUState HandleRelayResponse(RelayResponse response)
        {
            var cep = response.CharlieEndpoint;

            Logging.LogTransport($"SSU RelayRequestState: {Session.DebugId} RelayResponse {response}");

            var noncematch = Nonce == response.Nonce.Peek32(0);

            Logging.LogTransport($"SSU RelayRequestState: {Session.DebugId} Nonce match: {noncematch}");
            if (!noncematch)
            {
                return(this);
            }

            Session.RemoteEP = response.CharlieEndpoint;
            Session.Host.RelayResponseReceived -= Host_RelayResponseReceived;

            NextState = new SessionRequestState(Session);
            return(NextState);
        }
Esempio n. 6
0
        public override SSUState HandleMessage(SSUHeader header, BufRefLen reader)
        {
            DataSent();
#if LOG_ALL_TRANSPORT
            DebugUtils.Log("SSU EstablishedState +" + Session.TransportInstance.ToString() + "+ received: " +
                           header.MessageType.ToString() + ": " + SSUHost.SSUDateTime(header.TimeStamp).ToString());
#endif
            switch (header.MessageType)
            {
            case SSUHeader.MessageTypes.Data:
                try
                {
                    var datamsg = new SSUDataMessage(reader, Session.Defragmenter);
                    if (datamsg.ExplicitAcks != null)
                    {
                        Session.Fragmenter.GotAck(datamsg.ExplicitAcks);
                    }
                    if (datamsg.AckBitfields != null)
                    {
                        Session.Fragmenter.GotAck(datamsg.AckBitfields);
                    }
                    if (datamsg.NewMessages != null)
                    {
                        foreach (var msg in datamsg.NewMessages)
                        {
                            var i2npmsg = I2NPMessage.ReadHeader5((BufRefLen)msg.GetPayload());

#if LOG_ALL_TRANSPORT
                            DebugUtils.Log("SSU EstablishedState +" + Session.TransportInstance.ToString() + "+ complete message " +
                                           msg.MessageId.ToString() + ": " + i2npmsg.Expiration.ToString());
#endif

                            if (i2npmsg.MessageType == I2PCore.Tunnel.I2NP.Messages.I2NPMessage.MessageTypes.DeliveryStatus)
                            {
                                if (((DeliveryStatusMessage)i2npmsg.Message).IsNetworkId((ulong)I2PConstants.I2P_NETWORK_ID))
                                {
                                    continue;
                                }
                            }

                            Session.MessageReceived(i2npmsg);
                        }
                    }
                }
                catch (Exception ex)
                {
                    DebugUtils.Log("EstablishedState: SSUHost.SSUMessageTypes.Data", ex);
                }
                break;

            case SSUHeader.MessageTypes.SessionDestroyed:
                DebugUtils.LogDebug(() => string.Format("SSU EstablishedState {0}: SessionDestroyed received.", Session.DebugId));
                SendSessionDestroyed();
                return(null);

            case SSUHeader.MessageTypes.PeerTest:
                HandleIncomingPeerTestPackage(reader);
                break;

            case SSUHeader.MessageTypes.RelayResponse:
                DebugUtils.LogDebug(() => string.Format("SSU EstablishedState {0}: RelayResponse received from {1}.",
                                                        Session.DebugId, Session.RemoteEP));
                var response = new RelayResponse(reader);
                Session.Host.ReportRelayResponse(header, response, Session.RemoteEP);
                break;

            case SSUHeader.MessageTypes.RelayIntro:
                var intro = new RelayIntro(reader);
                DebugUtils.LogDebug(() => $"SSU EstablishedState {Session.DebugId}: RelayIntro received from {Session.RemoteEP} for {intro.AliceEndpoint}.");
                Session.Host.Send(intro.AliceEndpoint, new BufLen(new byte[0]));
                break;

            case SSUHeader.MessageTypes.RelayRequest:
                // if ( !SSUHost.IntroductionSupported ) throw new Exception( "SSU relay introduction not supported" );
                DebugUtils.LogDebug(() => string.Format("SSU EstablishedState {0}: Relay introduction not supported.", Session.DebugId));
                break;

            case SSUHeader.MessageTypes.SessionRequest:
                DebugUtils.LogDebug(() => string.Format("SSU EstablishedState {0}: SessionRequest received. Ending session.", Session.DebugId));
                SendSessionDestroyed();
                return(null);

            default:
                DebugUtils.LogDebug(() => string.Format("SSU EstablishedState {0}: Unexpected message received: {1}.",
                                                        Session.DebugId, header.MessageType));
                break;
            }

            return(this);
        }