Ejemplo n.º 1
0
    internal void Inject(ReloadMessage reloadMsg) {

      if (reloadMsg.reload_message_body.RELOAD_MsgCode == RELOAD_MessageCode.Fetch_Answer) {  //resign StoredData

        ResourceId res_id = GateWay.getResIdforTransactionId(reloadMsg.TransactionID);
        GateWay.removeResIdforTransactionId(reloadMsg.TransactionID);

        FetchAns answ = (FetchAns)reloadMsg.reload_message_body;
        List<FetchKindResponse> fetchKindResponses = answ.KindResponses;
        foreach (FetchKindResponse kind in fetchKindResponses) {
          foreach (StoredData sd in kind.values) {
            sd.SignData(res_id, kind.kind, ReloadConfig.AccessController.MyIdentity, ReloadConfig);
            ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING, "GW: DATA RESIGNED!");
          }
        }
      }

      reloadMsg.security_block = new SecurityBlock(ReloadConfig, ReloadConfig.AccessController.MyIdentity);
      reloadMsg.security_block.SignMessage(ReloadConfig.OverlayHash, //TODO: remove overlayhash from glals
       reloadMsg.TransactionID.ToString(), reloadMsg.reload_message_body);
      ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING, "GW: " + reloadMsg.reload_message_body.RELOAD_MsgCode.ToString() + "Message resigned (new SecurityBlock)");

      Transport.receive_message(reloadMsg);

    }
Ejemplo n.º 2
0
    //verifies message signature and StoredData Signatures and authenticates the certificates used to sign the signatures
    internal bool Validate(ReloadMessage reloadMsg) {
      bool requestPermitted = ReloadConfig.AccessController.RequestPermitted(reloadMsg);
      if (reloadMsg.reload_message_body.RELOAD_MsgCode == RELOAD_MessageCode.Fetch_Answer) {  //verify StoredData signature
        ResourceId res_id = GateWay.getResIdforTransactionId(reloadMsg.TransactionID);

        FetchAns answ = (FetchAns)reloadMsg.reload_message_body;
        if (reloadMsg.reload_message_body.RELOAD_MsgCode == RELOAD_MessageCode.Fetch_Answer) {
          List<FetchKindResponse> fetchKindResponses = answ.KindResponses;
          foreach (FetchKindResponse kind in fetchKindResponses) {
            foreach (StoredData sd in kind.values) {
              if (!ReloadConfig.AccessController.validateDataSignature(res_id, kind.kind, sd)) {
                kind.values.Remove(sd);
                ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING, "GW: DATA SIGNATURE INVALID!! => dropped");
              }
              else
                ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING, "GW: INCOMING DATA SIGNATURE VALID!!");
            }
          }
        }
      }
      if (requestPermitted) {
        ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING, "GW: INCOMING MESSAGE VERIFIED");
        return true;
      }
      else {
        ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING, "GW: INCOMING MESSAGE NOT VERIFIED!!!!!!!!!!!!!!!!");
        return false;
      }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Method is used to retrieve fragmented Messages. Needs to be called for every fragmented Message. Message fragments are stored in the fragmentedMessageBuffer.
        /// </summary>
        /// <param name="fragmentedMessageBuffer">reference to a buffer for MessageFragments</param>
        /// <returns name="fullmessage">Return reassembled Message in case all fragments have been received. Otherwise return value is null.</returns>
        public ReloadMessage ReceiveFragmentedMessage(ref Dictionary<ulong, SortedDictionary<UInt32, MessageFragment>> fragmentedMessageBuffer)
        {

            try
            {

                MessageFragment fragment = (MessageFragment)reload_message_body;

                StackTrace stackTrace = new StackTrace();

                if (!fragmentedMessageBuffer.ContainsKey(TransactionID))
                {
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FRAGMENTATION, String.Format(stackTrace.GetFrame(1).GetMethod().DeclaringType.FullName + ": FIRST Fragmented Message with TransID: {0} Offset: {1} ", TransactionID, fragment.Offset));
                    fragmentedMessageBuffer.Add(TransactionID, new SortedDictionary<UInt32, MessageFragment>());
                }
                else
                {
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FRAGMENTATION, String.Format(stackTrace.GetFrame(1).GetMethod().DeclaringType.FullName + ": Fragmented Message with TransID: {0} Offset: {1} ", TransactionID, fragment.Offset));
                }

                fragmentedMessageBuffer[TransactionID][fragment.Offset] = fragment;

                if (fragmentedMessageBuffer[TransactionID].Count >= 2)
                {  //check if all fragments have been received

                    SortedDictionary<UInt32, MessageFragment> dict = fragmentedMessageBuffer[TransactionID];    //sort after fragmentation offset

                    if (dict.First().Value.Offset != 0)
                        return null;  //first fragment missing

                    if (dict.Last().Value.LastFragment != true)
                        return null;  //last fragment missing

                    int received_payload = 0;
                    foreach (KeyValuePair<UInt32, MessageFragment> pair in dict)
                    {
                        if (received_payload != pair.Key)
                            return null;
                        received_payload += pair.Value.PayloadLength;
                    }

                    //Okay alles da => zusammenpacken

                    MemoryStream ms = new MemoryStream();
                    BinaryWriter writer = new BinaryWriter(ms);

                    bool header = false;
                    foreach (KeyValuePair<UInt32, MessageFragment> pair in dict)
                    {
                        //we need the header and take the header from the last received message TODO: this can be done better
                        if (header == false)
                        {
                            //ForwardingHeader forwarding_header = forwarding_header;
                            /* First save RELO Tag */
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((int)ReloadMessage.RELOTAG));
                            /* overlay */
                            //TODO
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((int)forwarding_header.overlay));
                            /* configuration_sequence */
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((short)forwarding_header.configuration_sequence));
                            /* version */
                            writer.Write((Byte)forwarding_header.version);
                            /* ttl */
                            writer.Write((Byte)forwarding_header.ttl);
                            /* fragment */
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder(0));    //no longer fragmented
                            /* length */
                            long forwarding_header_length_pos = ms.Position;
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((int)forwarding_header.length));
                            /* transaction_id */
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((long)forwarding_header.transaction_id));
                            /* max_response_length */
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((int)forwarding_header.max_response_length));

                            /* via_list_length */
                            long via_list_length_pos = ms.Position;
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((short)forwarding_header.via_list_length));            //just placeholder
                            /* destination_list_length */
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((short)forwarding_header.destination_list_length));    //just placeholder
                            /* options_length */
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((short)forwarding_header.options_length));             //just placeholder

                            forwarding_header.via_list_length = (ushort)ReloadMessage.WriteDestList(writer, forwarding_header.via_list);
                            forwarding_header.destination_list_length = (ushort)ReloadMessage.WriteDestList(writer, forwarding_header.destination_list);
                            forwarding_header.options_length = (ushort)ReloadMessage.WriteOptionList(writer, forwarding_header.fw_options);

                            long headerEndPosition = ms.Position;
                            ms.Seek(via_list_length_pos, SeekOrigin.Begin);
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((short)forwarding_header.via_list_length));
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((short)forwarding_header.destination_list_length));
                            writer.Write(System.Net.IPAddress.HostToNetworkOrder((short)forwarding_header.options_length));
                            ms.Seek(headerEndPosition, SeekOrigin.Begin);

                            header = true;
                        }

                        pair.Value.Dump(writer);

                    }

                    fragmentedMessageBuffer.Remove(TransactionID);
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FRAGMENTATION, String.Format("Message reassembled: Length={0}", ms.Length));

                    long bytesProcessed = 0;
                    byte[] temp = ms.ToArray();
                    ReloadMessage fullMsg = new ReloadMessage(m_ReloadConfig).FromBytes(temp, ref bytesProcessed, ReloadMessage.ReadFlags.full);
                    fullMsg.LastHopNodeId = this.LastHopNodeId;

                    return fullMsg;
                }
                else
                    return null;
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Checks if a inbound message must be forwarded
    /// 
    /// Returns true, if it will be forwarded
    /// </summary>
    /// <param name="reloadMsg">The inbound msg</param>
    /// <returns>true, if the message will be forwarded</returns>
    public bool ProcessMsg(ReloadMessage reloadMsg) {
      if (reloadMsg.OriginatorID == m_topology.LocalNode.Id) {
        if (m_loopedTransactions != null)
          m_loopedTransactions.Post(reloadMsg.TransactionID);
        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
          String.Format("Looped back and dropped {0} <== {1} TransId={2:x16}",
          reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '),
          reloadMsg.OriginatorID, reloadMsg.TransactionID));
        lock ("print via") {
          if (reloadMsg.forwarding_header.via_list != null)
            foreach (Destination via in reloadMsg.forwarding_header.via_list)
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                String.Format("Via: {0}", via));
        }
        return true;
      }

      //check for validity
      if (reloadMsg.forwarding_header.destination_list == null ||
          reloadMsg.forwarding_header.destination_list.Count == 0) {
        //empty destination list, reply with error
        m_transport.send(m_transport.create_erro_reply(
          new Destination(m_topology.LocalNode.Id),
            RELOAD_ErrorCode.Error_Unsupported_Forwarding_Option,
            "Empty destination list", ++m_ReloadConfig.TransactionID),
            m_topology.routing_table.GetNode(reloadMsg.LastHopNodeId));
        return true;
      }


    NextDestination:

      //check first entry on destination list
      Destination dest = reloadMsg.forwarding_header.destination_list[0];

      if (reloadMsg.forwarding_header.via_list != null) {
        // check for a remarkable lenght of via headers, they should not exceed a special value (MAX_VIA_LIST_ENTRIES)
        if (reloadMsg.forwarding_header.via_list.Count > ReloadGlobals.MAX_VIA_LIST_ENTRIES) {
          m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
             String.Format("==> maximum via list length exceeded {0}: {1} from {2} Dest={3} TransID={4:x16}",
             ReloadGlobals.MAX_VIA_LIST_ENTRIES,
             reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '),
             reloadMsg.OriginatorID, dest.ToString(), reloadMsg.TransactionID));

          if (reloadMsg.forwarding_header.via_list != null) {
            foreach (Destination destx in reloadMsg.forwarding_header.via_list)
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO,
                String.Format("Via={0} ", destx.ToString()));
          }
          if (reloadMsg.forwarding_header.destination_list != null) {
            foreach (Destination desty in reloadMsg.forwarding_header.destination_list)
              if (desty.type != DestinationType.node ||
                  reloadMsg.forwarding_header.destination_list.Count > 1)
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO,
                  String.Format("    Dest={0} ", desty.ToString()));
          }
          return true;
        }
      }

      switch (dest.type) {
        case DestinationType.node:

          NodeId DestinationId = dest.destination_data.node_id;

          /* some loop checks first */
          if (m_topology.LocalNode.Id == reloadMsg.OriginatorID) {
            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING,
              String.Format("==> Suspicious: packet looped back to me: {0} from {1} Dest={2} TransID={3:x16}",
              reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '),
              reloadMsg.OriginatorID, dest.ToString(), reloadMsg.TransactionID));
          }

          if (DestinationId == reloadMsg.OriginatorID) {
            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
              String.Format("Loop Warning: Node {0} tries to attach to itself, last hop={1} dropping request TransID={2:x16}", reloadMsg.OriginatorID, reloadMsg.LastHopNodeId, reloadMsg.TransactionID));
            if (reloadMsg.forwarding_header.via_list != null) {
              foreach (Destination destx in reloadMsg.forwarding_header.via_list)
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("    Via={0} ", destx.ToString()));
            }
            if (reloadMsg.forwarding_header.destination_list != null) {
              foreach (Destination desty in reloadMsg.forwarding_header.destination_list)
                if (desty.type != DestinationType.node || reloadMsg.forwarding_header.destination_list.Count > 1)
                  m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO,
                    String.Format("    Dest={0} ", desty.ToString()));
            }
            return true;
          }

          if (reloadMsg.forwarding_header.via_list != null) {
            foreach (Destination destination in reloadMsg.forwarding_header.via_list) {
              if (destination.type == DestinationType.node &&
                destination.destination_data.node_id == DestinationId) {
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING,
                  String.Format("==> packet looped back to me I'm already in via list: {0} from {1} Dest={2} TransID={3:x16}", reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '), reloadMsg.OriginatorID, dest.ToString(), reloadMsg.TransactionID));
                if (reloadMsg.forwarding_header.via_list != null) {
                  foreach (Destination destx in reloadMsg.forwarding_header.via_list)
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("    Via={0} ", destx.ToString()));
                }
                if (reloadMsg.forwarding_header.destination_list != null) {
                  foreach (Destination desty in reloadMsg.forwarding_header.destination_list)
                    if (desty.type != DestinationType.node || reloadMsg.forwarding_header.destination_list.Count > 1)
                      m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("    Dest={0} ", desty.ToString()));
                }
              }
            }
          }

          //is this this node?
          if (DestinationId == m_topology.LocalNode.Id || DestinationId == ReloadGlobals.WildcardNodeId) {
            //one single entry only?
            if (reloadMsg.forwarding_header.destination_list.Count == 1)
              //message for local node
              return false;
            else {
              //remove local node from destination list
              reloadMsg.RemoveFirstDestEntry();
              reloadMsg.AddViaHeader(m_topology.LocalNode.Id);
              if (handleInterdomainMessage(reloadMsg))
                return true; //message was processed! forwarded via GateWay!
              goto NextDestination;
            }
          }

          Node NextHopNode = null;

          foreach (ReloadConnectionTableInfoElement rce in m_flm.ConnectionTable) {
            if (rce.NodeID != null && rce.NodeID == DestinationId) {
              NextHopNode = m_topology.routing_table.GetNode(DestinationId);
              break;
            }
          }

          /* Do we have ice candidates already from destination?  */
          if (NextHopNode == null)
            if (m_topology.routing_table.IsAttached(DestinationId))
              NextHopNode = m_topology.routing_table.GetNode(DestinationId);

          /* no direct physical parameters available? -> use routing */
          if (NextHopNode == null)
            /*  The Topology Plugin is responsible for maintaining the overlay
                algorithm Routing Table, which is consulted by the Forwarding and
                Link Management Layer before routing a message. 
             */

            NextHopNode = m_topology.routing_table.FindNextHopTo(
              dest.destination_data.node_id, true, false);

          if (NextHopNode == null || NextHopNode.Id == m_topology.LocalNode.Id) {
            if (reloadMsg.OriginatorID != m_topology.LocalNode.Id) {
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                String.Format("==> failed forwarding: {0} from {1} Dest={2}" +
                " TransID={3:x16}",
                reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '),
                reloadMsg.OriginatorID, dest.ToString(), reloadMsg.TransactionID));
              m_transport.send(m_transport.create_erro_reply(
                new Destination(reloadMsg.OriginatorID),
                RELOAD_ErrorCode.Error_Not_Found,
                "Node not found", ++m_ReloadConfig.TransactionID),
                m_topology.routing_table.GetNode(reloadMsg.LastHopNodeId));
            }
          }
          else {
            if (NextHopNode.Id == reloadMsg.OriginatorID) {
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING,
                String.Format("Topo claims Originator responsible:" +
                " {0} from {1} Dest={2} TransID={3:x16}",
                reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '),
                reloadMsg.OriginatorID, dest.ToString(), reloadMsg.TransactionID));
            }

            if (reloadMsg.IsRequest()) {
              reloadMsg.AddViaHeader(m_topology.LocalNode.Id);
            }
            //else
            //  reloadMsg.PutViaListToDestination();

            reloadMsg.LastHopNodeId = m_topology.LocalNode.Id;

                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING,
                  String.Format("==> forwarding: {0} from {1} ==> {2}  Dest={3} TransID={4:x16}",
                  reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '),
                  reloadMsg.OriginatorID, NextHopNode.ToString(), dest.ToString(),
                  reloadMsg.TransactionID));

                m_transport.send(reloadMsg, NextHopNode);
          }
          break;
        case DestinationType.resource: {
            DestinationId = new NodeId(dest.destination_data.ressource_id);
            NodeId test = new NodeId(HexStringConverter.ToByteArray(
              "464201D3D1BDA43AC047ECD75CE6201D"));
            if (DestinationId == test)
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_USAGE, "");
            /*  The Topology Plugin is responsible for maintaining the overlay
                algorithm Routing Table, which is consulted by the Forwarding and
                Link Management Layer before routing a message. 
             */

            if (DestinationId == m_topology.LocalNode.Id) // || (m_topology.routing_table.Predecessors.Count > 0 &&
              //DestinationId.ElementOfInterval(m_topology.routing_table.Predecessors[0], m_ReloadConfig.LocalNodeID, false)))
              //message for local node
              return false;

            /* be carefull here, if this request looped back to us, exclude us from the possible forwarding targets
             */
            NextHopNode = m_topology.routing_table.FindNextHopTo(DestinationId, true, m_topology.LocalNode.Id == reloadMsg.OriginatorID);

            if (NextHopNode == null) {
              //we did not found another node responsible, so we are => message for local node
              return false;
            }
            else if (NextHopNode.Id == m_topology.LocalNode.Id) {
              //silently drop packet if there is more then one entry in destination list
              if (reloadMsg.forwarding_header.destination_list.Count > 1)
                break;
              //message for local node
              return false;
            }
            else {
              if (reloadMsg.IsRequest())
                reloadMsg.AddViaHeader(m_topology.LocalNode.Id);
              else
                reloadMsg.RemoveFirstDestEntry();

                  m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING,
                    String.Format("==> forwarding: {0} from {1} ==> {2} Dest={3} TransID={4:x16}",
                    reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '),
                    reloadMsg.OriginatorID, NextHopNode.ToString(), dest.ToString(),
                    reloadMsg.TransactionID));
                  /*  don't use create_reload* as it puts via header to destination   */
                  m_transport.send(reloadMsg, NextHopNode);
            }
          }
          break;
        case DestinationType.compressed:
          //empty destination list, reply with error
          m_transport.send(m_transport.create_erro_reply(
            new Destination(reloadMsg.OriginatorID),
            RELOAD_ErrorCode.Error_Unsupported_Forwarding_Option,
            "Compressed destination type not supported",
            ++m_ReloadConfig.TransactionID),
            m_topology.routing_table.GetNode(reloadMsg.LastHopNodeId));
          break;
      }
      return true;
    }
Ejemplo n.º 5
0
 /// <summary>
 /// TASK: Execute this dialog by sending the buffer and start reception.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <param name="rx_filter">The rx_filter.</param>
 /// <param name="rx_timeout">The rx_timeout.</param>
 /// <returns></returns>
 public IEnumerator<ITask> Execute(ReloadMessage reloadMessage, ReloadMessageFilter rx_filter, int rx_timeout) {
     //m_Transport.Send(this.m_NextHopNode, reloadMessage);
     Arbiter.Activate(m_DispatcherQueue, new IterativeTask<Node, ReloadMessage>(this.m_NextHopNode, reloadMessage, m_Transport.Send));
     m_TimeStart = DateTime.Now;
     //m_MessageFilter = rx_filter;
     Arbiter.Activate(m_DispatcherQueue, new IterativeTask<ReloadMessageFilter, int, String>(rx_filter, rx_timeout, reloadMessage.reload_message_body.RELOAD_MsgCode.ToString(), Receive));
     yield break;
 }
Ejemplo n.º 6
0
 private IEnumerator<ITask> Send(ReloadMessage reloadMessage) {
     //m_Transport.Send(this.m_NextHopNode, reloadMessage);
     Arbiter.Activate(m_DispatcherQueue, new IterativeTask<Node, ReloadMessage>(this.m_NextHopNode, reloadMessage, m_Transport.Send));
     m_TimeStart = DateTime.Now;
     yield break;
 }
Ejemplo n.º 7
0
 public ReloadMessage create_reload_message(ReloadMessage reloadRequest)
 {
     try
     {
         reloadRequest.PutViaListToDestination();
     }
     catch (Exception ex)
     {
         m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
           "create_reload_message: " + ex.Message);
     }
     return reloadRequest;
 }
Ejemplo n.º 8
0
        private void reload_leave_inbound(ReloadMessage recmsg)
        {
            LeaveReqAns req_answ = (LeaveReqAns)recmsg.reload_message_body;
            NodeId OriginatorID = recmsg.OriginatorID;

            if (req_answ.RELOAD_MsgCode == RELOAD_MessageCode.Leave_Request)
            {

                // Leaving nodes will be stored for 2 minutes to make sure we do not learn about them again
                m_topology.routing_table.AddLeavingNode(req_answ.LeavingNode);

                m_topology.InboundLeave(req_answ.LeavingNode);
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD, String.Format("{0} ==> {1} TransId={2:x16}",
                    RELOAD_MessageCode.Leave_Answer.ToString().PadRight(16, ' '), OriginatorID, recmsg.TransactionID));

                ReloadMessage sendmsg = create_leave_answ(new Destination(OriginatorID), recmsg.TransactionID);
                recmsg.PutViaListToDestination(sendmsg);

                send(sendmsg, m_topology.routing_table.GetNode(recmsg.LastHopNodeId));
            }
            else
            {
            }
        }
Ejemplo n.º 9
0
    /// <summary>
    /// Deserializes AccessControlList Kind from byte stream.
    /// </summary>
    /// <param name="rm">Not used.</param>
    /// <param name="reader">Binary reader containing message byte stream.</param>
    /// <param name="usage_size">Not used. ACL has fix length.</param>
    /// <returns></returns>
    public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long usage_size) {
      codePoint = Usage_Code_Point.ACCESS_LIST;
      UInt16 len = 0; // for opaque string lengths
      try {
        /* read resource_name*/
        len = (UInt16)(System.Net.IPAddress.HostToNetworkOrder((short)reader.ReadInt16()));
        resource_name = Encoding.UTF8.GetString(reader.ReadBytes(len), 0, len);
        /* read length of PDU */
        length = (UInt16)(System.Net.IPAddress.HostToNetworkOrder((short)reader.ReadInt16()));
        /* read to_user value */
        len = (UInt16)(System.Net.IPAddress.HostToNetworkOrder((short)reader.ReadInt16()));
        string to_uri = Encoding.UTF8.GetString(reader.ReadBytes(len), 0, len);
        /* read kindId to be shared */
        UInt32 kindId = (UInt32)System.Net.IPAddress.NetworkToHostOrder((int)reader.ReadInt32());
        /* read allow_delegation flag */
        Boolean allow_delegation = (reader.ReadByte() == 0 ? false : true);
        /* Create ACL data */
        data = new AccessListData(kindId, to_uri, allow_delegation);

        usage_size = usage_size - (length + 1);

      }
      catch (Exception ex) {
        myManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
            String.Format("AccessList FromReader(): {0}", ex.Message));
      }
      SetHashCode();
      return this;
    }
Ejemplo n.º 10
0
 /// <summary>
 /// Deserializes a DisCoRegistration from byte stream.
 /// </summary>
 /// <param name="rm">Not used.</param>
 /// <param name="reader">
 /// The binary reader containing the entire RELOAD message</param>
 /// <param name="usage_size">Not used. DisCoReg has fixed length</param>
 /// <returns></returns>
 public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long usage_size) {
   codePoint = Usage_Code_Point.DISCO;
   UInt16 len = 0; // used for length of opaque values            
   try {
     /* lenght of resource name and resource name */
     len = (UInt16)(Conv.NetworkToHostOrder((short)reader.ReadInt16()));
     resourceName = Encoding.ASCII.GetString(reader.ReadBytes(len), 0, len);
     /* length of rest PDU */
     length = (UInt16)(Conv.NetworkToHostOrder((short)reader.ReadInt16()));
     /* length of coordiate and coordinate */
     len = (UInt16)(Conv.NetworkToHostOrder((short)reader.ReadInt16()));
     string coord = Encoding.UTF8.GetString(reader.ReadBytes(len), 0, len);
     /* node_id of remote peer */
     NodeId nodeId = new NodeId(reader.ReadBytes(ReloadGlobals.NODE_ID_DIGITS));
     /* Instanciate DisCo data */
     data = new DisCoRegistrationData(coord, nodeId);
     usage_size = usage_size - (length + 1);
   }
   catch (Exception ex) {
     myManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
         String.Format("DisCoRegistration FromBytes(): {0}", ex.Message));
   }
   return this;
 }
Ejemplo n.º 11
0
 public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long usage_size) {
   throw new NotImplementedException();
 }
Ejemplo n.º 12
0
    /// <summary>
    /// Deserializes a Usage object from wire.
    /// </summary>
    /// <param name="reader">The reader. It MUST be desesiralied until the DataValue struct including the Boolean exists value.</param>
    /// <param name="KindId">An UInt32 carrying the Kinde Code Point to this Usage.</param>
    /// <returns></returns>
    public IUsage GetUsageFromReader(ReloadMessage rm, BinaryReader reader, long usage_length, UInt32 kindId) {

      foreach (IUsage usage in usages.Values) {
        if (usage.KindId == kindId)
          return usage.FromReader(rm, reader, usage_length);
      }
      throw new NotSupportedException(String.Format("Kind ID {0} is not supported!", kindId));
    }
Ejemplo n.º 13
0
    public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long usage_size)
    {
      try
      {
        long posBefore = reader.BaseStream.Position;
        var type = (CertificateType)reader.ReadByte();
        var unknown = reader.ReadByte();
        UInt16 len = (UInt16)IPAddress.NetworkToHostOrder(reader.ReadInt16());
        //TElX509Certificate cert = new TElX509Certificate();
        //Byte[] bcert = reader.ReadBytes(len);
        //cert.LoadFromBuffer(bcert);
        long posAfter = reader.BaseStream.Position;

        usage_size = usage_size - (posAfter - posBefore);
        length = (uint)(posAfter - posBefore); //TK not sure if this is correct
      }
      catch (Exception ex)
      {
        throw ex;
      }
      return this;
    }
Ejemplo n.º 14
0
    public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long usage_size) //REDIR_SERVICE_PROVIDER
    {
      codePoint = Usage_Code_Point.REDIR_SERVICE_PROVIDER;

      UInt16 namespacelength;
      string nameSpace;
      UInt16 level;
      UInt16 node;
      NodeId serviceProviderID;

      try {
        uint length = (UInt32)(System.Net.IPAddress.NetworkToHostOrder((int)reader.ReadInt32()));

        UInt16 serviceProviderID_len = (UInt16)(System.Net.IPAddress.NetworkToHostOrder(reader.ReadInt16()));
        serviceProviderID = new NodeId(reader.ReadBytes(serviceProviderID_len));

        namespacelength = (UInt16)(System.Net.IPAddress.NetworkToHostOrder(reader.ReadInt16()));

        nameSpace = Encoding.ASCII.GetString(reader.ReadBytes(namespacelength)); //ASCII for wireshark dissector

        level = (UInt16)(System.Net.IPAddress.NetworkToHostOrder(reader.ReadInt16()));

        node = (UInt16)(System.Net.IPAddress.NetworkToHostOrder(reader.ReadInt16()));

        string resourceName = (nameSpace + "," + level + "," + node);

        RedirServiceProvider serviceProvider = new RedirServiceProvider(serviceProviderID, resourceName, nameSpace, level, node, myManager);

        return serviceProvider;
      }
      catch (Exception ex) {
        throw ex;
      }
    }
Ejemplo n.º 15
0
	public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long reload_msg_size)
	{
		ImageStoreUsage result = new ImageStoreUsage(UsageManager);
		var ASCII = Encoding.ASCII;
		var bytesCount = 0;

		try
		{
			// Deserialize the ResourceName
			{
				bytesCount = IPAddress.NetworkToHostOrder(reader.ReadInt32());
				result.ResourceName = ASCII.GetString(reader.ReadBytes(bytesCount), 0, bytesCount);
			}

			// Deserialize the ImageStoreData
			{
				var nodeId = new NodeId(reader.ReadBytes(ReloadGlobals.NODE_ID_DIGITS));

				bytesCount = IPAddress.NetworkToHostOrder(reader.ReadInt32());
				var name = ASCII.GetString(reader.ReadBytes(bytesCount), 0, bytesCount);

				var width = IPAddress.NetworkToHostOrder(reader.ReadInt16());

				var height = IPAddress.NetworkToHostOrder(reader.ReadInt16());

				bytesCount = IPAddress.NetworkToHostOrder(reader.ReadInt32());
				var data = reader.ReadBytes(bytesCount);

				result.Data = new ImageStoreData(nodeId, name, width, height, data);
			}

			// Compute the total usage length
			result.Length = 0
				+ (uint)(result.ResourceName.Length + 2)
				+ (uint)(result.Data.NodeId.Digits)
				+ (uint)(result.Data.Name.Length + 2)
				+ (uint)(2)
				+ (uint)(2)
				+ (uint)(result.Data.Data.Length + 2);
		}
		catch (Exception exception)
		{
			UsageManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
				 String.Format("ImageStoreUsage.FromBytes(): {0}", exception.Message));
		}

		return result;
	}
Ejemplo n.º 16
0
        /// <summary>
        /// Handles incoming fetch requests
        /// </summary>
        /// <param name="recmsg"></param>
        private void reload_fetch_inbound(ReloadMessage recmsg)
        {

            ReloadMessage sendmsg;

            if (recmsg.IsRequest())
            {
                FetchReq fetchRequest = (FetchReq)recmsg.reload_message_body;
                NodeId originatorId = recmsg.OriginatorID;

                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD,
                  String.Format("{0} ==> {1} TransId={2:x16}",
                    RELOAD_MessageCode.Fetch_Answer.ToString().PadRight(16, ' '),
                      originatorId, recmsg.TransactionID));

                // List of SignerIdentities of the data to be fetched
                List<SignerIdentity> signers = new List<SignerIdentity>();

                var fetchKindResponses = new List<FetchKindResponse>();
                foreach (StoredDataSpecifier specifier in fetchRequest.Specifiers)
                {
                    FetchKindResponse fetchKindResponse;
                    if (m_topology.Fetch(fetchRequest.ResourceId,
                        specifier, out fetchKindResponse))
                    {
                        fetchKindResponses.Add(fetchKindResponse);

                        // add certificate
                        foreach (StoredData data in fetchKindResponse.values)
                            if (!signers.Contains(data.Signature.Identity))
                                signers.Add(data.Signature.Identity);
                    }
                    else
                    {
                        sendmsg = create_erro_reply(new Destination(originatorId),
                          RELOAD_ErrorCode.Error_Not_Found,
                            "Topology: RessourceId not found", recmsg.TransactionID);
                        recmsg.PutViaListToDestination(sendmsg);
                        send(sendmsg, m_topology.routing_table.GetNode(recmsg.LastHopNodeId));

                        return;
                    }
                }

                sendmsg = create_fetch_answ(new Destination(originatorId), recmsg.TransactionID, fetchKindResponses);

                // get certificates for this data
                List<GenericCertificate> certs = new List<GenericCertificate>();
                certs.AddRange(m_ReloadConfig.AccessController.GetPKCs(signers));

                // add certificates to fetch answer
                sendmsg.security_block.Certificates.AddRange(certs);

                recmsg.PutViaListToDestination(sendmsg);
                //sendmsg.addOverlayForwardingOptions(recmsg);  //Proprietary  //--Joscha	

                if (m_machine is GWMachine)
                { //workaround in case date is stored at the gateway node responsible to route the message back into the interconnectionoverlay 
                    if (sendmsg.forwarding_header.destination_list[0].destination_data.node_id == ((GWMachine)m_machine).GateWay.interDomainPeer.Topology.LocalNode.Id)
                    {
                        sendmsg.reload_message_body.RELOAD_MsgCode = RELOAD_MessageCode.Fetch_Answer;
                        ((GWMachine)m_machine).GateWay.interDomainPeer.Inject(sendmsg); //TODO: change other cases
                    }
                    else
                        send(sendmsg, m_topology.routing_table.GetNode(recmsg.LastHopNodeId));
                }
                else
                    send(sendmsg, m_topology.routing_table.GetNode(recmsg.LastHopNodeId));
            }
            else
            {
                // It is a FetchAns, no reply needed
            }
        }
Ejemplo n.º 17
0
        private void reload_ping_inbound(ReloadMessage recmsg)
        {
            PingReqAns req_answ = (PingReqAns)recmsg.reload_message_body;
            NodeId originatorID = recmsg.OriginatorID;

            if (recmsg.IsRequest())
            {
                // is still my Finger?
                /*
                Topology.RoutingTable.FTableEntry ftEntry;
                if (m_topology.routing_table.isFinger(originatorID, out ftEntry)) {
                  if (m_topology.routing_table.IsAttached(originatorID))
                    Arbiter.Activate(m_DispatcherQueue,
                        new IterativeTask<Topology.RoutingTable.FTableEntry, ReloadMessage>(
                        ftEntry, recmsg, AttachFinger));
                }
                 */

                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD,
                  String.Format("{0} ==> {1} TransId={2:x16}",
                  RELOAD_MessageCode.Ping_Answer.ToString().PadRight(16, ' '),
                  originatorID, recmsg.TransactionID));

                ReloadMessage sendmsg = create_ping_answ(new Destination(originatorID), recmsg.TransactionID);

                recmsg.PutViaListToDestination(sendmsg);

                send(sendmsg, m_topology.routing_table.GetNode(recmsg.LastHopNodeId));
            }
            else
            {
            }
        }
Ejemplo n.º 18
0
    /// <summary>
    /// This method reads deserializes a SipRegistration datagramm from incomming bytes.
    /// </summary>
    /// <param name="rm">The ReloadMessage helper class</param>
    /// <param name="reader">The incomming byte stream reader</param>
    /// <param name="usage_size">Size of the Usage datagramm.</param>
    /// <returns></returns>
    public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long usage_size) {
      try {
        type = (SipRegistrationType)reader.ReadByte();
        this.length = (UInt16)(IPAddress.HostToNetworkOrder(
          (short)reader.ReadInt16()));
        switch (type) {
          case SipRegistrationType.sip_registration_uri:
            UInt16 len = (UInt16)(IPAddress.HostToNetworkOrder((short)reader.ReadInt16()));
            data = new SipRegistrationData(Encoding.UTF8.GetString(reader.ReadBytes(len), 0, len));
            break;

          case SipRegistrationType.sip_registration_route:
            len = (UInt16)(IPAddress.HostToNetworkOrder((short)reader.ReadInt16()));
            string contact_prefs = Encoding.UTF8.GetString(reader.ReadBytes(len), 0, len);

            len = (UInt16)(IPAddress.HostToNetworkOrder((short)reader.ReadInt16()));
            data = new SipRegistrationData(contact_prefs, rm.ReadDestList(reader, len));
            break;
          default:
            throw new SystemException(String.Format("Invalid SipRegistrationType {0}!", type));
        }

        usage_size = usage_size - (length);

      }
      catch (Exception ex) {
        throw ex;
      }
      return this;
    }
Ejemplo n.º 19
0
        public void receive_message(ReloadMessage reloadMsg)
        {
            if (m_ReloadConfig.State == ReloadConfig.RELOAD_State.Exit)
                return;

            try
            {
                if (reloadMsg == null)
                {
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "receive_message: reloadMsg = null!!");
                    return;
                }

                if (reloadMsg.IsFragmented() && reloadMsg.IsSingleFragmentMessage() == false)
                {  // -- joscha
                    ReloadMessage reassembledMsg = null;
                    lock (fragmentedMessageBuffer)
                    {
                        reassembledMsg = reloadMsg.ReceiveFragmentedMessage(ref fragmentedMessageBuffer);
                    }
                    if (reassembledMsg == null) //not yet all fragments received => not reassembled
                        return;
                    else
                        reloadMsg = reassembledMsg; //message reassembled => continue as usual
                }

                //is this a request to be forwarded?
                if (!m_forwarding.ProcessMsg(reloadMsg))
                {
                    /* First of all, validate message */
                    if (!m_ReloadConfig.AccessController.RequestPermitted(reloadMsg))
                    {
                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                          "Transport.receive_message(): " + reloadMsg.reload_message_body.RELOAD_MsgCode.ToString() + " Request originator cannot be validated!");
                        return;
                    }

                    /* handle only incoming RELOAD requests here...,
                     * all answers will be handled in the appropriate tasks
                     */
                    if (reloadMsg.IsRequest())
                    {
                        //message for local node
                        if (reloadMsg.reload_message_body.RELOAD_MsgCode == RELOAD_MessageCode.Store_Request)
                        {
                            StoreReq storeRequest = (StoreReq)reloadMsg.reload_message_body;
                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD, String.Format("{0} <== {1} TransId={2:x16} Replicanumber={3}", reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '), reloadMsg.OriginatorID, reloadMsg.TransactionID, storeRequest.Replica_number));
                        }
                        else
                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD, String.Format("{0} <== {1} TransId={2:x16}", reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '), reloadMsg.OriginatorID, reloadMsg.TransactionID));

                        if (reloadMsg.forwarding_header.via_list != null)
                        {
                            try
                            {
                                foreach (Destination destx in reloadMsg.forwarding_header.via_list)
                                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("    Via={0} ", destx.ToString()));
                            }
                            catch (Exception ex)
                            {
                                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "receive_message, ReloadMsg viaList" + ex.Message);
                            }
                        }
                        if (reloadMsg.forwarding_header.destination_list != null)
                        {
                            try
                            {
                                foreach (Destination desty in reloadMsg.forwarding_header.destination_list)
                                    if (desty.type != DestinationType.node || reloadMsg.forwarding_header.destination_list.Count > 1)
                                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("    Dest={0} ", desty.ToString()));
                            }
                            catch (Exception ex)
                            {
                                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "receive_message, ReloadMsg destList" + ex.Message);
                            }
                        }

                        switch (reloadMsg.reload_message_body.RELOAD_MsgCode)
                        {
                            case RELOAD_MessageCode.Probe_Request:
                            case RELOAD_MessageCode.Probe_Answer:
                                break;
                            case RELOAD_MessageCode.Attach_Request:
                            case RELOAD_MessageCode.Attach_Answer:
                                reload_attach_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Store_Request:
                                reload_store_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Store_Answer:
                                reload_store_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Fetch_Request:
                                reload_fetch_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Fetch_Answer:
                                reload_fetch_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Remove_Request:
                            case RELOAD_MessageCode.Remove_Answer:
                                break;
                            case RELOAD_MessageCode.Find_Request:
                            case RELOAD_MessageCode.Find_Answer:
                                break;
                            case RELOAD_MessageCode.Join_Request:
                            case RELOAD_MessageCode.Join_Answer:
                                reload_join_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Leave_Request:
                            case RELOAD_MessageCode.Leave_Answer:
                                reload_leave_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Update_Request:
                            case RELOAD_MessageCode.Update_Answer:
                                reload_update_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Route_Query_Request:
                            case RELOAD_MessageCode.Route_Query_Answer:
                                break;
                            case RELOAD_MessageCode.Ping_Request:
                                reload_ping_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Ping_Answer:
                                reload_ping_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Stat_Request:
                            case RELOAD_MessageCode.Stat_Answer:
                                break;
                            case RELOAD_MessageCode.App_Attach_Request:
                            case RELOAD_MessageCode.App_Attach_Answer:
                                reload_app_attach_inbound(reloadMsg);
                                break;
                            case RELOAD_MessageCode.Error:
                                {
                                    ErrorResponse errorResponse = (ErrorResponse)reloadMsg.reload_message_body;
                                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("<== Error {0} Msg: {1}", errorResponse.ErrorCode, errorResponse.ErrorMsg));
                                }
                                break;
                            case RELOAD_MessageCode.Unused:
                            case RELOAD_MessageCode.Unused2:
                            default:
                                throw new System.Exception(String.Format("Invalid RELOAD message type {0}", reloadMsg.reload_message_body.RELOAD_MsgCode));
                        }
                    }
                    else
                    {

                        /* m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD,
                          String.Format("{0} <== {1}", 
                          reloadMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '),
                          reloadMsg.OriginatorID));
                         */
                        /*
                        switch (reloadMsg.reload_message_body.RELOAD_MsgCode) {
                            case RELOAD_MessageCode.Attach_Answer:
                                reload_attach_inbound((AttachReqAns)reloadMsg.reload_message_body, reloadMsg.OriginatorID, reloadMsg.TransID(), reloadMsg.LastHopNodeId);
                                break;
                            default:
                                throw new System.Exception(String.Format("Invalid RELOAD message type {0}", reloadMsg.reload_message_body.RELOAD_MsgCode));
                        }*/

                        if (!ReloadGlobals.UseNoIce)     // markus
                        {
                            // we use ICE
                            if (reloadMsg.reload_message_body.RELOAD_MsgCode == RELOAD_MessageCode.Attach_Answer)
                            {
                                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("Attach Answer Transaction ID: {0:x}", reloadMsg.TransactionID));

                                // forward attach answer
                                reload_attach_inbound(reloadMsg);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "receive_message: " + ex.Message);
                ReloadGlobals.PrintException(m_ReloadConfig, ex);
                //System.Diagnostics.Debugger.Break();
            }
        }
Ejemplo n.º 20
0
 public IEnumerator<ITask> Send(ReloadMessage reloadSendMsg, Node NextHopNode)
 {
     if (reloadSendMsg.reload_message_body.RELOAD_MsgCode ==
       RELOAD_MessageCode.Error)
         m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
           String.Format("{0} ==> {1} code={2}: msg=\"{3}\", dest={4}",
           reloadSendMsg.reload_message_body.RELOAD_MsgCode.ToString().PadRight(16, ' '),
           NextHopNode, ((ErrorResponse)reloadSendMsg.reload_message_body).ErrorCode,
           ((ErrorResponse)reloadSendMsg.reload_message_body).ErrorMsg,
           reloadSendMsg.forwarding_header.destination_list[0]));
     try
     {
         Arbiter.Activate(m_DispatcherQueue, new IterativeTask<Node, ReloadMessage>(NextHopNode, reloadSendMsg, GetForwardingAndLinkManagementLayer().Send));
     }
     catch (Exception ex)
     {
         m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
           "SendAnswer: " + ex.Message);
     }
     yield break;
 }
Ejemplo n.º 21
0
        internal void send(ReloadMessage reloadMsg, Node NextHopNode)
        {

            if (NextHopNode == null || NextHopNode.Id == null)
                throw new System.Exception("Node == null on send");
            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("!!! send: !!! {0} to {1}", Enum.GetName(typeof(RELOAD_MessageCode), reloadMsg.reload_message_body.RELOAD_MsgCode), reloadMsg.forwarding_header.destination_list[0]));
            if (m_ReloadConfig.State < ReloadConfig.RELOAD_State.Exit)
                Arbiter.Activate(m_DispatcherQueue,
                  new IterativeTask<ReloadMessage, Node>(reloadMsg, NextHopNode, Send));
        }
Ejemplo n.º 22
0
        public void reload_attach_inbound(ReloadMessage recmsg)
        {

            try
            {
                AttachReqAns req_answ = (AttachReqAns)recmsg.reload_message_body;
                NodeId OriginatorID = recmsg.OriginatorID;

                if (req_answ != null && req_answ.ice_candidates != null)
                {
                    //if (ReloadGlobals.UseNoIce || m_ReloadConfig.IsBootstrap)
                    //{
                    //Node attacher = new Node(recmsg.OriginatorID, req_answ.ice_candidates);           // markus, moved down
                    //bool isFinger = m_topology.routing_table.isFinger(attacher.Id);

                    //m_topology.routing_table.AddNode(attacher);
                    //m_topology.routing_table.SetNodeState(recmsg.OriginatorID, NodeState.attached);
                    //}


                    // incoming ATTACH REQUEST, so localnode is controlled agent
                    if (recmsg.IsRequest())
                    {

                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD,
                                      String.Format("{0} ==> {1} TransId={2:x16}",
                                      RELOAD_MessageCode.Attach_Answer.ToString().PadRight(16, ' '),
                                      OriginatorID, recmsg.TransactionID));

                        ReloadMessage sendmsg = create_attach_answ(
                          new Destination(OriginatorID), recmsg.TransactionID);

                        // log output
                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("Attach Request: Transaction ID: {0:x}", recmsg.TransactionID));

                        foreach (IceCandidate cand in ((AttachReqAns)sendmsg.reload_message_body).ice_candidates)
                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("Attach Request: Gathered local candidate for Answer: {0}:{1} (TransId: {2:x})", cand.addr_port.ipaddr.ToString(), cand.addr_port.port, sendmsg.TransactionID));

                        foreach (IceCandidate cand in req_answ.ice_candidates)
                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("Attach Request: Received remote candidate: {0}:{1} (TransId: {2:x})", cand.addr_port.ipaddr.ToString(), cand.addr_port.port, recmsg.TransactionID));


                        recmsg.PutViaListToDestination(sendmsg);
                        //sendmsg.addOverlayForwardingOptions(recmsg);  //Proprietary  //--Joscha	
                        if (m_machine is GWMachine)
                        { //workaround in case date is stored at the gateway node responsible to route the message back into the interconnectionoverlay 
                            if (sendmsg.forwarding_header.destination_list[0].destination_data.node_id == ((GWMachine)m_machine).GateWay.interDomainPeer.Topology.LocalNode.Id)
                            {
                                sendmsg.reload_message_body.RELOAD_MsgCode = RELOAD_MessageCode.Fetch_Answer;
                                ((GWMachine)m_machine).GateWay.interDomainPeer.Transport.receive_message(sendmsg);
                            }
                            else
                                send(sendmsg, m_topology.routing_table.GetNode(recmsg.LastHopNodeId));
                        }
                        else
                        {
                            send(sendmsg, m_topology.routing_table.GetNode(recmsg.LastHopNodeId));
                        }




                        // markus
                        if (!ReloadGlobals.UseNoIce) // using ICE
                        {
                            // we only need ICE processing if localnode is a peer (in case of bootstrap we need no checks)
                            if (!m_ReloadConfig.IsBootstrap)
                            {

                                #region ICE TODO
                                // localnode is Peer => ICE processing (this is controlled node)
                                AttachReqAns attachAnswer = (AttachReqAns)sendmsg.reload_message_body;

                                // deep copy of local and remote ice candidates
                                List<IceCandidate> localIceCandidatesCopy = new List<IceCandidate>();
                                List<IceCandidate> remoteIceCandidatesCopy = new List<IceCandidate>();

                                // local candidates
                                foreach (IceCandidate cand in attachAnswer.ice_candidates)
                                {
                                    IceCandidate deepCopy = (IceCandidate)cand.Clone();
                                    localIceCandidatesCopy.Add(deepCopy);
                                }

                                // remote candidates
                                foreach (IceCandidate cand in req_answ.ice_candidates)
                                {
                                    IceCandidate deepCopy = (IceCandidate)cand.Clone();
                                    remoteIceCandidatesCopy.Add(deepCopy);
                                }

                                // now form check list
                                //CheckList checkList = ICE.FormCheckList(attachAnswer.ice_candidates, req_answ.ice_candidates, false);
                                CheckList checkList = ICE.FormCheckList(localIceCandidatesCopy, remoteIceCandidatesCopy, false);

                                ICE.PrintCandidatePairList(checkList.candidatePairs);

                                Console.WriteLine("ThreadId: {0}, send_params einfügen: checkList count {1}", Thread.CurrentThread.ManagedThreadId, checkList.candidatePairs.Count);
                                // Add to connection queue
                                for (int i = 0; i < checkList.candidatePairs.Count; i++)
                                {
                                    ReloadSendParameters send_params = new ReloadSendParameters()
                                    {
                                        connectionTableEntry = null,
                                        destinationAddress = checkList.candidatePairs[i].remoteCandidate.addr_port.ipaddr,
                                        port = checkList.candidatePairs[i].remoteCandidate.addr_port.port,
                                        buffer = null,
                                        frame = false,
                                        done = new Port<bool>(),
                                        // markus
                                        connectionSocket = null,
                                    };


                                    // if key already exists => skip
                                    if (!GetForwardingAndLinkManagementLayer().GetConnectionQueue().ContainsKey(checkList.candidatePairs[i].remoteCandidate))
                                        GetForwardingAndLinkManagementLayer().GetConnectionQueue().Add(checkList.candidatePairs[i].remoteCandidate, send_params);

                                }

                                ICE.ScheduleChecks(checkList, m_ReloadConfig.Logger);

                                // Wait for signals of all succeded candidate pairs. Only one of the succeded candidate pairs is nominated
                                #region signaling
                                // wait for nomination signal
                                List<Thread> waitingThreads = new List<Thread>();

                                foreach (CandidatePair candPair in checkList.candidatePairs)
                                {
                                    if (candPair.state == CandidatePairState.Succeeded)
                                    {
                                        switch (candPair.localCandidate.tcpType)
                                        {
                                            case TcpType.Active:
                                                {
                                                    if (candPair.localCandidate.activeConnectingSocket != null)
                                                    {
                                                        Thread waitThread = new Thread(() =>
                                                        {
                                                            candPair.nominated = ICE.WaitForSignal(candPair.localCandidate.activeConnectingSocket);
                                                        });
                                                        waitingThreads.Add(waitThread);
                                                        waitThread.Start();
                                                    }
                                                }
                                                break;

                                            case TcpType.Passive:
                                                {
                                                    if (candPair.localCandidate.passiveAcceptedSocket != null)
                                                    {
                                                        Thread waitThread = new Thread(() =>
                                                        {
                                                            candPair.nominated = ICE.WaitForSignal(candPair.localCandidate.passiveAcceptedSocket);
                                                        });
                                                        waitingThreads.Add(waitThread);
                                                        waitThread.Start();
                                                    }
                                                }
                                                break;

                                            case TcpType.SO:
                                                {
                                                    if (candPair.localCandidate.soAcceptedSocket != null)
                                                    {
                                                        Thread waitThread = new Thread(() =>
                                                        {
                                                            candPair.nominated = ICE.WaitForSignal(candPair.localCandidate.soAcceptedSocket);
                                                        });
                                                        waitingThreads.Add(waitThread);
                                                        waitThread.Start();
                                                    }

                                                    else if (candPair.localCandidate.soConnectingSocket != null)
                                                    {
                                                        Thread waitThread = new Thread(() =>
                                                        {
                                                            candPair.nominated = ICE.WaitForSignal(candPair.localCandidate.soConnectingSocket);
                                                        });
                                                        waitingThreads.Add(waitThread);
                                                        waitThread.Start();
                                                    }
                                                }
                                                break;

                                        }   // switch
                                    }   // if
                                }   // foreach

                                // wait for all threads
                                foreach (Thread waitingThread in waitingThreads)
                                {
                                    waitingThread.Join();
                                }
                                #endregion


                                // choose pair
                                CandidatePair choosenPair = null;

                                // any nominated pair?
                                if (checkList.candidatePairs.Any(item => item.nominated == true))
                                {
                                    choosenPair = checkList.candidatePairs.First(item => item.nominated == true);
                                }

                                // Close all sockets of all candidate pairs not nominated
                                //for (int i = 0; i < checkList.candidatePairs.Count; i++)
                                //    if ((!checkList.candidatePairs[i].nominated) || (checkList.candidatePairs[i].state != CandidatePairState.Succeeded))
                                //        ICE.CloseAllCandidateSockets(checkList.candidatePairs[i].localCandidate);

                                // add node with chosen remote candidate
                                if (choosenPair != null)
                                {

                                    // save connection
                                    //GetForwardingAndLinkManagementLayer().SaveConnection(choosenPair);

                                    // get connection
                                    Socket socket = GetForwardingAndLinkManagementLayer().GetConnection(choosenPair);

                                    // Get IPAdress and Port of the attacher from attachers certificate cn
                                    System.Security.Cryptography.X509Certificates.X509Certificate2 tempcert = new System.Security.Cryptography.X509Certificates.X509Certificate2(recmsg.security_block.Certificates[0].Certificate);
                                    IPEndPoint attacherEndpoint =
                                        new IPEndPoint(IPAddress.Parse(tempcert.SubjectName.Name.ToString().Split(':')[1]),
                                                       Convert.ToInt32( tempcert.SubjectName.Name.ToString().Split(':')[2]));
                                    // StartReloadTLSClient
                                    GetForwardingAndLinkManagementLayer().StartReloadTLSClient(OriginatorID, socket, attacherEndpoint);

                                    // for all candidates send_params.done = true
                                    for (int i = 0; i < checkList.candidatePairs.Count; i++)
                                    {
                                        ReloadSendParameters send_params;

                                        GetForwardingAndLinkManagementLayer().GetConnectionQueue().TryGetValue(checkList.candidatePairs[i].remoteCandidate, out send_params);

                                        if (send_params != null)
                                        {
                                            send_params.done.Post(true);

                                            // remove from connection queue
                                            GetForwardingAndLinkManagementLayer().GetConnectionQueue().Remove(checkList.candidatePairs[i].remoteCandidate);
                                        }
                                    }

                                    List<IceCandidate> choosenRemoteCandidates = new List<IceCandidate>();
                                    choosenRemoteCandidates.Add(choosenPair.remoteCandidate);

                                    Node attacher = new Node(recmsg.OriginatorID, choosenRemoteCandidates);
                                    bool isFinger = m_topology.routing_table.isFinger(attacher.Id);

                                    m_topology.routing_table.AddNode(attacher);
                                    m_topology.routing_table.SetNodeState(recmsg.OriginatorID, NodeState.attached);
                                }

                                // free all port mappings created by UPnP
                                foreach (IceCandidate cand in attachAnswer.ice_candidates)
                                {
                                    if (cand.cand_type == CandType.tcp_nat)
                                    {
                                        UPnP upnp = new UPnP();
                                        bool discovered = upnp.Discover(cand.rel_addr_port.ipaddr);

                                        if (discovered)
                                            upnp.DeletePortMapping(cand.addr_port.port, ProtocolType.Tcp);
                                    }
                                }


                                #endregion

                            }


                            else
                            {
                                // localnode is bootstrap => no ICE processing

                                Node attacher = new Node(recmsg.OriginatorID, req_answ.ice_candidates);
                                bool isFinger = m_topology.routing_table.isFinger(attacher.Id);

                                m_topology.routing_table.AddNode(attacher);
                                m_topology.routing_table.SetNodeState(recmsg.OriginatorID, NodeState.attached);

                            }


                        }

                        // using NO ICE
                        else
                        {

                            Node attacher = new Node(recmsg.OriginatorID, req_answ.ice_candidates);
                            bool isFinger = m_topology.routing_table.isFinger(attacher.Id);

                            m_topology.routing_table.AddNode(attacher);
                            m_topology.routing_table.SetNodeState(recmsg.OriginatorID, NodeState.attached);
                        }
                        // markus end



                        if (req_answ.SendUpdate)
                            Arbiter.Activate(m_DispatcherQueue, new IterativeTask<Node, Node>(
                              m_topology.routing_table.GetNode(OriginatorID),
                              m_topology.routing_table.GetNode(recmsg.LastHopNodeId),
                              SendUpdate));



                    }

                    // incoming ATTACH ANSWER, so localnode is controlling agent
                    // and localnode must be a peer, because bootstraps dont create attach requests and because of this cant receive an attach answer
                    else
                    {
                        // using NOICE
                        if (ReloadGlobals.UseNoIce)     // markus: added if/else statement
                        {
                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                              String.Format("{0} <== {1} (not handled!!)",
                              req_answ.RELOAD_MsgCode.ToString().PadRight(16, ' '), OriginatorID));
                        }

                        // using ICE
                        else
                        {
                            // get local candidates from request
                            List<IceCandidate> localCandidates = null;
                            bool gotLocalCandidate = m_attachRequestCandidates.TryGetValue(recmsg.TransactionID, out localCandidates);

                            // log output
                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("Attach Answer: Transaction ID: {0:x}", recmsg.TransactionID));
                            foreach (IceCandidate cand in localCandidates)
                                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("Attach Answer: Got local candidate: {0}:{1} (TransId: {2:x})", cand.addr_port.ipaddr.ToString(), cand.addr_port.port, recmsg.TransactionID));

                            foreach (IceCandidate cand in req_answ.ice_candidates)
                                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("Attach Answer: Received remote candidate: {0}:{1} (TransId: {2:x})", cand.addr_port.ipaddr.ToString(), cand.addr_port.port, recmsg.TransactionID));


                            if (req_answ.ice_candidates != null)
                            {
                                // we need ice, except the answering peer is a bootstrap
                                bool needIce = true;

                                //// bootstrap responses with only one candidate
                                //if (req_answ.ice_candidates.Count == 1)
                                //{
                                // is it really a bootstrap?
                                if (req_answ.ice_candidates[0].cand_type == CandType.tcp_bootstrap)
                                {
                                    // attached to a bootstrap, so we have to do nothing here, no ice processing needed
                                    needIce = false;
                                }

                                //}

                                if (needIce)
                                {
                                    #region ICE TODO
                                    // ICE processing (this is controlling node)
                                    if (gotLocalCandidate)
                                    {
                                        // deep copy of remote ice candidates
                                        List<IceCandidate> remoteIceCandidatesCopy = new List<IceCandidate>();

                                        // remote candidates
                                        foreach (IceCandidate cand in req_answ.ice_candidates)
                                        {
                                            IceCandidate deepCopy = (IceCandidate)cand.Clone();
                                            remoteIceCandidatesCopy.Add(deepCopy);
                                        }

                                        //CheckList checkList = ICE.FormCheckList(localCandidates, req_answ.ice_candidates, true);
                                        CheckList checkList = ICE.FormCheckList(localCandidates, remoteIceCandidatesCopy, true);

                                        ICE.PrintCandidatePairList(checkList.candidatePairs);

                                        ICE.ScheduleChecks(checkList, m_ReloadConfig.Logger);

                                        m_attachRequestCandidates.Remove(recmsg.TransactionID);

                                        #region signaling

                                        // any succeeded pair?
                                        if (checkList.candidatePairs.Any(item => item.state == CandidatePairState.Succeeded))
                                        {
                                            // get all succeeded pairs
                                            List<CandidatePair> succeededPairs = checkList.candidatePairs.Where(item => item.state == CandidatePairState.Succeeded).ToList();

                                            // send nomination signal to peer
                                            bool sentSuccessfull = false;
                                            bool nominated;
                                            int counter = 0;

                                            foreach (CandidatePair pair in succeededPairs)
                                            {
                                                // simply nominate the first succeeded pair
                                                if (counter == 0)
                                                    nominated = true;
                                                else
                                                    nominated = false;

                                                switch (pair.localCandidate.tcpType)
                                                {
                                                    case TcpType.Active:
                                                        {
                                                            if (pair.localCandidate.activeConnectingSocket != null)
                                                            {
                                                                sentSuccessfull = ICE.SendSignal(pair.localCandidate.activeConnectingSocket, nominated);
                                                                pair.nominated = nominated;
                                                            }
                                                        }
                                                        break;

                                                    case TcpType.Passive:
                                                        {
                                                            if (pair.localCandidate.passiveAcceptedSocket != null)
                                                            {
                                                                sentSuccessfull = ICE.SendSignal(pair.localCandidate.passiveAcceptedSocket, nominated);
                                                                pair.nominated = nominated;
                                                            }
                                                        }
                                                        break;

                                                    case TcpType.SO:
                                                        {
                                                            if (pair.localCandidate.soAcceptedSocket != null)
                                                            {
                                                                sentSuccessfull = ICE.SendSignal(pair.localCandidate.soAcceptedSocket, nominated);
                                                                pair.nominated = nominated;
                                                            }

                                                            else if (pair.localCandidate.soConnectingSocket != null)
                                                            {
                                                                sentSuccessfull = ICE.SendSignal(pair.localCandidate.soConnectingSocket, nominated);
                                                                pair.nominated = nominated;
                                                            }
                                                        }
                                                        break;

                                                }   // switch

                                                counter++;

                                            }   // foreach


                                            if (sentSuccessfull)
                                            {

                                            }


                                        #endregion  // signaling


                                            // Start Server here, if a nominated pair exists
                                            if (checkList.candidatePairs.Any(item => item.nominated))
                                            {
                                                CandidatePair choosenPair = checkList.candidatePairs.First(item => item.nominated);

                                                // save connection here too?
                                                //GetForwardingAndLinkManagementLayer().SaveConnection(choosenPair);

                                                // get connection
                                                Socket socket = GetForwardingAndLinkManagementLayer().GetConnection(choosenPair);

                                                // StartReloadTLSServer
                                                GetForwardingAndLinkManagementLayer().StartReloadTLSServer(socket);
                                            } // if (any nominated)


                                        }   // if (any succeeded pair)

                                        // Close all sockets of all candidate pairs not nominated
                                        //for (int i = 0; i < checkList.candidatePairs.Count; i++)
                                        //    if ((!checkList.candidatePairs[i].nominated) || (checkList.candidatePairs[i].state != CandidatePairState.Succeeded))
                                        //        ICE.CloseAllCandidateSockets(checkList.candidatePairs[i].localCandidate);
                                    }

                                    #endregion  // ICE

                                }

                                // existing nat candidates to free?
                                if (localCandidates != null)
                                {
                                    // free all port mappings created by UPnP
                                    foreach (IceCandidate cand in localCandidates)
                                    {
                                        if (cand.cand_type == CandType.tcp_nat)
                                        {
                                            UPnP upnp = new UPnP();
                                            bool discovered = upnp.Discover(cand.rel_addr_port.ipaddr);

                                            if (discovered)
                                                upnp.DeletePortMapping(cand.addr_port.port, ProtocolType.Tcp);

                                        }
                                    }
                                }

                            }

                        }


                    }
                }
            }
            catch (Exception e)
            {

                throw;
            }

        }
Ejemplo n.º 23
0
        public void reload_app_attach_inbound(ReloadMessage recmsg)
        {
            AppAttachReqAns req_answ = (AppAttachReqAns)recmsg.reload_message_body;
            NodeId OriginatorID = recmsg.OriginatorID;
            Node Originator = new Node(recmsg.OriginatorID, req_answ.ice_candidates);

            m_topology.routing_table.AddNode(Originator);
            m_topology.routing_table.SetNodeState(Originator.Id, NodeState.attached);

            //Proprietary --joscha
            string destination_overlay = null;
            string source_overlay = null;

            if (recmsg.forwarding_header.fw_options != null)
            {

                foreach (ForwardingOption option in recmsg.forwarding_header.fw_options)
                {
                    if (option.fwo_type == ForwardingOptionsType.destinationOverlay)
                    {
                        destination_overlay = System.Text.Encoding.Unicode.GetString(option.bytes);
                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("{0} Message  for destinationOverlay=" + destination_overlay, recmsg.reload_message_body.RELOAD_MsgCode));
                    }
                    if (option.fwo_type == ForwardingOptionsType.sourceOverlay)
                    {
                        source_overlay = System.Text.Encoding.Unicode.GetString(option.bytes);
                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("Message from sourceOverlay=" + source_overlay));
                    }
                }
            }

            if (destination_overlay == null)// --joscha Do not establish a connection to a different overlay    
                if (CheckAndSetAdmittingPeer(Originator) && Originator.Id != recmsg.LastHopNodeId)
                    // Send ping to establish a physical connection
                    Arbiter.Activate(m_DispatcherQueue,
                      new IterativeTask<Destination, PingOption>(new Destination(Originator.Id),
                      PingOption.direct, SendPing));

            if (source_overlay == m_ReloadConfig.OverlayName)
            {

                // Send ping to establish a physical connection
                Arbiter.Activate(m_DispatcherQueue,
                  new IterativeTask<Destination, PingOption>(new Destination(Originator.Id),
                  PingOption.direct, SendPing));
            }
            if (req_answ != null && req_answ.ice_candidates != null)
            {
                if (recmsg.IsRequest())
                {

                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("transport.cs - reload_app_attach_inbound"));

                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD,
                      String.Format("{0} ==> {1} TransId={2:x16}",
                      RELOAD_MessageCode.App_Attach_Answer.ToString().PadRight(16, ' '),
                      OriginatorID, recmsg.TransactionID));

                    ReloadMessage sendmsg = create_app_attach_answ(
                      new Destination(OriginatorID), recmsg.TransactionID);
                    recmsg.PutViaListToDestination(sendmsg);
                    //sendmsg.addOverlayForwardingOptions(recmsg);  //--joscha
                    send(sendmsg, m_topology.routing_table.GetNode(recmsg.LastHopNodeId));
                }
                else
                {
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("{0} <== {1} (not handled!!)", req_answ.RELOAD_MsgCode.ToString().PadRight(16, ' '), OriginatorID));
                }
            }
        }
Ejemplo n.º 24
0
        private void reload_join_inbound(ReloadMessage recmsg)
        {
            JoinReqAns req_answ = (JoinReqAns)recmsg.reload_message_body;
            NodeId OriginatorID = recmsg.OriginatorID;

            if (recmsg.IsRequest())
            {
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD, String.Format("{0} ==> {1} TransId={2:x16}",
                    RELOAD_MessageCode.Join_Answer.ToString().PadRight(16, ' '), OriginatorID, recmsg.TransactionID));
                /* leaving Address and port empty, that should already be stored in link management tables */

                // 5.  JP MUST send a Join to AP.  The AP sends the response to the
                // Join. RELOAD base -13 .105
                ReloadMessage sendmsg = create_join_answ(new Destination(OriginatorID), recmsg.TransactionID);
                recmsg.PutViaListToDestination(sendmsg);
                send(sendmsg, m_topology.routing_table.GetNode(recmsg.LastHopNodeId));

                /*  AP MUST send JP an Update explicitly labeling JP as its predecessor. */
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("Send update on join"));
                Arbiter.Activate(m_DispatcherQueue,
                  new IterativeTask<Node, Node>(
                  m_topology.routing_table.GetNode(OriginatorID),
                  m_topology.routing_table.GetNode(recmsg.LastHopNodeId), SendUpdate));

                if (m_ReloadConfig.IsBootstrap && m_ReloadConfig.State != ReloadConfig.RELOAD_State.Joined)
                {
                    m_ReloadConfig.State = ReloadConfig.RELOAD_State.Joined;
                    m_machine.StateUpdates(ReloadConfig.RELOAD_State.Joined);
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO,
                      String.Format("Changed to joined state"));
                }
            }
            else
            {
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// TASK: Waits for the reception for max rx_timeout milliseconds. Filters if required.
        /// </summary>
        /// <param name="rx_filter">The rx_filter.</param>
        /// <param name="rx_timeout">The rx_timeout.</param>
        /// <returns></returns>
        private IEnumerator<ITask> Receive(ReloadMessageFilter rx_filter, int rx_timeout, String messageCode) {

            m_DispatcherQueue.EnqueueTimer(TimeSpan.FromMilliseconds(rx_timeout), timeouted);
            m_fError = false;
            bool fTimeouted = false;
            
            //m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TEST, String.Format("Receiver {0} started", rx_filter.transactionID));

            /* there are multiple incoming packets possible, if there wasn't a matching packet so far, 
             * wait for it as long there is no timout condition
             */
            while (!fTimeouted && m_ReloadConfig.State < ReloadConfig.RELOAD_State.Exit)
            {
                yield return Arbiter.Choice(
                    Arbiter.Receive(false, timeouted, to =>
                    {
                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING, String.Format("Receiver {0} Rx Timeout after sending {1}", rx_filter.transactionID, messageCode));
                        fTimeouted = true;
                    }),
                    Arbiter.Receive(false, m_portWaitForRx, trigger =>
                    {
                        //m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TEST, String.Format("Receiver {0} released, error is {1}", rx_filter.transactionID, error));
                    }));

                    if (!fTimeouted && !m_fError)
                        while (m_Queue.Count != 0 && m_ReloadConfig.State < ReloadConfig.RELOAD_State.Exit)
                        {
                            
                            ReloadFLMEventArgs args = (ReloadFLMEventArgs)m_Queue.Dequeue();

                            if (args == null || args.Message == null)
                            {
                                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("Receive: Args == null"));
                                break;
                            }

                            if (args.Eventtype == ReloadFLMEventArgs.ReloadFLMEventTypes.RELOAD_EVENT_RECEIVE_OK)
                            {
                                ReloadMessage reloadMsg = args.Message;
                                
                                if (reloadMsg == null)
                                {
                                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("Receive: Dropping invalid packet from {0}", args.ConnectionTableEntry != null ? args.ConnectionTableEntry.NodeID.ToString() : "unknown"));
                                    break;
                                }
                                //m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("Receiver {0} Queuecount {1} Transactionid: {2}", rx_filter.transactionID, m_Queue.Count, reloadMsg.TransactionID));
                                if (reloadMsg.IsFragmented() && reloadMsg.IsSingleFragmentMessage() == false && rx_filter != null && reloadMsg.TransactionID == rx_filter.transactionID) 
                                {
                                  ReloadMessage reassembledMsg = null;
                                  lock (fragmentedMessageBuffer) {
                                    reassembledMsg = reloadMsg.ReceiveFragmentedMessage(ref fragmentedMessageBuffer);
                                  }
                                    if (reassembledMsg == null) //not yet all fragments received => not reassembled
                                    {
                                      Arbiter.Activate(m_DispatcherQueue, new IterativeTask<ReloadMessageFilter, int, String>(rx_filter, rx_timeout, "", Receive));
                                      m_TimeStart = DateTime.Now;
                                      yield break;
                                    }
                                    else
                                      reloadMsg = reassembledMsg; //message reassembled => continue as usual
                                }

                                if (args.ConnectionTableEntry != null)
                                    m_SourceNodeID = args.ConnectionTableEntry.NodeID;
                                else
                                    m_SourceNodeID = reloadMsg.LastHopNodeId;

                                if (rx_filter != null)
                                {
                                    //                              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TEST, String.Format("Receiver {0} Checking against {1}", rx_filter.transactionID, reloadMsg.TransactionID));

                                    /* Most important part: Do only accept messages with the same transaction id
                                     * this ReloadDialog had been registered to and ignore the rest                */
                                    if (reloadMsg.TransactionID == rx_filter.transactionID)
                                    {
                                        if (!reloadMsg.IsRequest())
                                        {
                                            //m_ReceivedMessage = args.Message;
                                            m_ReceivedMessage = reloadMsg; //--joscha
                                            /* just a trick to get out of the parent loop */
                                            fTimeouted = true;
                                            break;
                                        }
                                        else
                                        {
                                          /* Our Request looped back to us, module Forwarding is handling this */

                                          if (reloadMsg.reload_message_body.RELOAD_MsgCode == RELOAD_MessageCode.Error) {
                                            if (((ErrorResponse)reloadMsg.reload_message_body).ErrorCode == RELOAD_ErrorCode.Error_Not_Found) { // --joscha not found response => don't wait for timeout
                                              m_ReceivedMessage = null;
                                              /* just a trick to get out of the parent loop */
                                              fTimeouted = true;
                                              break;
                                            }
                                          }
                                        }
                                    }
                                }
                                else
                                {
                                    /* No filter specified, deliver every packet */
                                    //m_ReceivedMessage = args.Message;
                                    m_ReceivedMessage = reloadMsg; //--joscha;
                                    /* just a trick to get out of the parent loop */
                                    fTimeouted = true;
                                    break;
                                }
                            }
                        }
            }
            m_Transport.ReloadFLMEventHandler -= OVL_ReloadForwardLinkManagementEventHandler;
            m_fDone.Post(true);
        }
Ejemplo n.º 26
0
        private void reload_update_inbound(ReloadMessage recmsg)
        {
            UpdateReqAns req_answ = (UpdateReqAns)recmsg.reload_message_body;
            NodeId OriginatorID = recmsg.OriginatorID;
            Boolean force_send_update = false;

            if (recmsg.IsRequest())
            {
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD,
                  String.Format("{0} ==> {1} TransId={2:x16}",
                  RELOAD_MessageCode.Update_Answer.ToString().PadRight(16, ' '),
                  OriginatorID, recmsg.TransactionID));

                ReloadMessage sendmsg = create_update_answ(
                  new Destination(OriginatorID), recmsg.TransactionID,
                  RELOAD_ErrorCode.invalid);

                recmsg.PutViaListToDestination(sendmsg);
                send(sendmsg, m_topology.routing_table.GetNode(recmsg.LastHopNodeId));
                //NodeId originator = recmsg.OriginatorID;
                m_topology.routing_table.SetNodeState(OriginatorID,
                  NodeState.updates_received);
                m_topology.routing_table.SetFingerState(OriginatorID,
                  NodeState.updates_received);
                if (req_answ.Successors.Count > 0)
                {
                    m_topology.routing_table.GetNode(OriginatorID).Successors = req_answ.Successors;
                    m_topology.routing_table.GetNode(OriginatorID).Predecessors = req_answ.Predecessors;
                }

                if (m_ReloadConfig.State == ReloadConfig.RELOAD_State.Joining)
                {
                    if (m_ReloadConfig.AdmittingPeer != null &&
                      OriginatorID == m_ReloadConfig.AdmittingPeer.Id)
                    {
                        if (!m_topology.routing_table.IsWaitForJoinAnsw(OriginatorID))
                        {
                            //we received an update from admitting peer, now joining is complete
                            m_ReloadConfig.State = ReloadConfig.RELOAD_State.Joined;
                            m_machine.StateUpdates(ReloadConfig.RELOAD_State.Joined);
                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD,
                              String.Format("Joining completed"));
                            m_ReloadConfig.LastJoinedTime = DateTime.Now;
                            force_send_update = true;
                        }
                    }
                }
                //inform topo about incoming update
                Arbiter.Activate(m_DispatcherQueue,
                  new IterativeTask<NodeId, UpdateReqAns, Boolean>(
                  OriginatorID, req_answ, force_send_update, m_topology.routing_table.Merge));

                // delete old entries in LeavingTable
                List<NodeId> expiredNodes = new List<NodeId>();
                foreach (KeyValuePair<NodeId, DateTime> entry in m_topology.routing_table.LeavingNodes)
                {
                    if (entry.Value.AddSeconds(300) < DateTime.Now)
                        expiredNodes.Add(entry.Key);
                }
                foreach (NodeId id in expiredNodes)
                    m_topology.routing_table.LeavingNodes.Remove(id);

            }
            else
            {
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TOPO, "Incoming UpdateAns");
            }
        }
Ejemplo n.º 27
0
    /// <summary>
    /// Checks if a inbound message contains inter-domain routing information
    /// 
    /// Returns true, if it will be forwarded
    /// </summary>
    /// <param name="reloadMsg">The inbound msg</param>
    /// <returns>true, if the message was processed as an inter-domain message</returns>
    /// 
    bool handleInterdomainMessage(ReloadMessage reloadMsg) {
      if (m_ReloadConfig.ThisMachine is TSystems.RELOAD.Extension.GWMachine) {
        TSystems.RELOAD.Extension.GWMachine gw = (TSystems.RELOAD.Extension.GWMachine)m_ReloadConfig.ThisMachine;
        
        if (!reloadMsg.IsRequest()) {
          NodeId nextHopId = reloadMsg.forwarding_header.destination_list[0].destination_data.node_id;
          if (nextHopId == gw.GateWay.interDomainPeer.Topology.Id) {
            gw.GateWay.response_processed(false);
            //---------------DEBUG
            gw.GateWay.interDomainPeer.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("interDomainPeer: handleInterdomainMessage via_list"));
            if (reloadMsg.forwarding_header.via_list != null) {
              foreach (Destination destx in reloadMsg.forwarding_header.via_list)
                gw.GateWay.interDomainPeer.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("    Via={0} ", destx.ToString()));
            }
            gw.GateWay.interDomainPeer.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("interDomainPeer: handleInterdomainMessage destination_list"));
            if (reloadMsg.forwarding_header.destination_list != null) {
              foreach (Destination desty in reloadMsg.forwarding_header.destination_list)
                gw.GateWay.interDomainPeer.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("    Dest={0} ", desty.ToString()));
            }
            //---------------DEBUG
            //gw.GateWay.interDomainPeer.Transport.receive_message(reloadMsg);
            if (gw.Validate(reloadMsg)) {
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING,
                "handleInterdomainMessage(): Response Signature verified and Signer Certificate authenticated");
              gw.GateWay.interDomainPeer.Inject(reloadMsg);
            }
            else
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                  "handleInterdomainMessage(): Response originator cannot be validated!");  
            return true;
          }
          else if (nextHopId == gw.GateWay.mainPeer.Topology.Id) {
            gw.GateWay.response_processed(true);
            //---------------DEBUG
            gw.GateWay.mainPeer.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("mainPeer: handleInterdomainMessage via_list"));
            if (reloadMsg.forwarding_header.via_list != null) {
              foreach (Destination destx in reloadMsg.forwarding_header.via_list)
                gw.GateWay.mainPeer.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("    Via={0} ", destx.ToString()));
            }
            gw.GateWay.mainPeer.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("mainPeer: handleInterdomainMessage destination_list"));
            if (reloadMsg.forwarding_header.destination_list != null) {
              foreach (Destination desty in reloadMsg.forwarding_header.destination_list)
                gw.GateWay.mainPeer.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("    Dest={0} ", desty.ToString()));
            }
            //---------------DEBUG
            //gw.GateWay.mainPeer.Transport.receive_message(reloadMsg);
            if (gw.Validate(reloadMsg)) {
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING,
                "handleInterdomainMessage(): Response Signature verified and Signer Certificate authenticated");
              gw.GateWay.mainPeer.Inject(reloadMsg);
            }
            else
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                  "handleInterdomainMessage(): Response originator cannot be validated!");
            return true;
          }
        }
        else if (reloadMsg.forwarding_header.fw_options != null) { //handle proprietary forwarding options destination_overlay and source_overlay --joscha
          string destination_overlay = null;
          string source_overlay = null;

          foreach (ForwardingOption option in reloadMsg.forwarding_header.fw_options) {
            if (option.fwo_type == ForwardingOptionsType.destinationOverlay) {
              destination_overlay = System.Text.Encoding.Unicode.GetString(option.bytes);
            }
            if (option.fwo_type == ForwardingOptionsType.sourceOverlay) {
              source_overlay = System.Text.Encoding.Unicode.GetString(option.bytes);
            }
          }
          if (destination_overlay != null) {
            //---------------DEBUG
            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format(" reloadMsg.forwarding_header.fw_options != null via_list"));
            if (reloadMsg.forwarding_header.via_list != null) {
              foreach (Destination destx in reloadMsg.forwarding_header.via_list)
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("    Via={0} ", destx.ToString()));
            }
            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format(" reloadMsg.forwarding_header.fw_options != null destination_list"));
            if (reloadMsg.forwarding_header.destination_list != null) {
              foreach (Destination desty in reloadMsg.forwarding_header.destination_list)
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("    Dest={0} ", desty.ToString()));
            }
            //---------------DEBUG
            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format(m_ReloadConfig.OverlayName + ": " + "for destinationOverlay: " + destination_overlay));
            if (gw.Validate(reloadMsg)) {
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FORWARDING,
                "handleInterdomainMessage(): Request Signature verified and Signer Certificate authenticated");
              gw.GateWay.Receive(destination_overlay, reloadMsg);
              return true;
            }   
          }
        }
      }
      return false;
    }
Ejemplo n.º 28
0
        /// <summary>
        /// Handles incoming StoreReq messages.
        /// </summary>
        /// <param name="recmg">The received RELOAD message</param>
        private void reload_store_inbound(ReloadMessage recmsg)
        {

            if (recmsg.IsRequest())
            {

                StoreReq storeRequest = (StoreReq)recmsg.reload_message_body;
                NodeId originatorID = recmsg.OriginatorID;
                List<StoreKindData> recStoreKindData;

                // TODO: For now add certificate to global PKC Store, but they are only temporarilly needed in validateDataSignature
                m_ReloadConfig.AccessController.SetPKCs(recmsg.security_block.Certificates);

                Boolean validRequest = true;

                recStoreKindData = storeRequest.StoreKindData;

                // validate data signature
                foreach (StoreKindData store_kind in recStoreKindData)
                {
                    foreach (StoredData sd in store_kind.Values)
                    {
                        if (!m_ReloadConfig.AccessController.validateDataSignature(storeRequest.ResourceId, store_kind.Kind, sd))
                        {
                            validRequest = false;
                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TOPO, "DATA SIGNATURE INVALID!! Store Failed!!");
                        }
                    }
                }

                if (storeRequest.Replica_number == 1)
                {
                    // find sender in my predecessors
                    int sender = m_topology.routing_table.Predecessors.IndexOf(recmsg.OriginatorID);

                    // sender not in my predecessors
                    if (sender < 0)
                        validRequest = false;

                    // we are able to perform validity checks
                    if (m_topology.routing_table.Predecessors.Count > 2)
                    {
                        if (!storeRequest.ResourceId.ElementOfInterval(m_topology.routing_table.Predecessors[sender + 1], m_topology.routing_table.Predecessors[sender], true))
                            // is the storing peer responsible for that resourceId?
                            validRequest = false;
                    }

                }

                // REPLICATEST
                if (validRequest)
                {
                    if (storeRequest.Replica_number == 1)
                    {
                        if (!m_topology.Replicas.Contains(storeRequest.ResourceId.ToString()))
                        {
                            m_topology.Replicas.Add(storeRequest.ResourceId.ToString());
                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ALL, String.Format("Add Ressource {0} as Replica", storeRequest.ResourceId.ToString()));
                        }
                    }

                    if (storeRequest.Replica_number == 0 && m_topology.Replicas.Contains(storeRequest.ResourceId.ToString()))
                    {
                        m_topology.Replicas.Remove(storeRequest.ResourceId.ToString());
                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ALL, String.Format("My Predecessor left. I'm now responsible for data {0}. Remove replica", storeRequest.ResourceId.ToString()));
                    }

                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_RELOAD,
                      String.Format("{0} ==> {1} via: {3:x20} TransId={2:x16}",
                      RELOAD_MessageCode.Store_Answer.ToString().PadRight(16, ' '),
                      originatorID, recmsg.TransactionID, recmsg.LastHopNodeId));

                    //recStoreKindData = storeRequest.StoreKindData;
                    foreach (StoreKindData store_kind in recStoreKindData)
                    {
                        m_topology.Store(storeRequest.ResourceId, store_kind);
                    }
                    /* It then sends a Store request to its successor in the neighbor
                     * table and to that peer's successor.
                     * 
                     * see RELOAD base -12 p.104
                     */
                    List<NodeId> replicaNodes = new List<NodeId>();

                    NodeId successor = m_topology.routing_table.GetApprovedSuccessor();
                    BigInt nextSuccsessor = successor + 1;
                    NodeId successorsSuccessor = m_topology.routing_table.FindNextHopTo(
                      new NodeId(nextSuccsessor.Data), true, false).Id;
                    replicaNodes.Add(successor);
                    replicaNodes.Add(successorsSuccessor);

                    // send StoreAns to originator
                    ReloadMessage storeAnswer = create_store_answ(
                      new Destination(originatorID), recmsg.TransactionID, recStoreKindData,
                      replicaNodes);
                    recmsg.PutViaListToDestination(storeAnswer);
                    //storeAnswer.addOverlayForwardingOptions(recmsg);  //Proprietary  //--Joscha	

                    Node nextHop = m_topology.routing_table.GetNode(recmsg.LastHopNodeId);
                    if (m_machine is GWMachine)
                    { //workaround in case date is stored at the gateway node responsible to route the message back into the interconnectionoverlay 
                        if (storeAnswer.forwarding_header.destination_list[0].destination_data.node_id == ((GWMachine)m_machine).GateWay.interDomainPeer.Topology.LocalNode.Id)
                        {
                            storeAnswer.reload_message_body.RELOAD_MsgCode = RELOAD_MessageCode.Fetch_Answer;
                            ((GWMachine)m_machine).GateWay.interDomainPeer.Transport.receive_message(storeAnswer);
                        }
                        else
                            send(storeAnswer, nextHop);
                    }
                    else
                        send(storeAnswer, nextHop);

                    // REPLICATEST
                    // incoming store request is not a replication request
                    if (storeRequest.Replica_number == 0)
                    {
                        int numberReplicas = m_topology.routing_table.Successors.Count >= 2 ? 2 : m_topology.routing_table.Successors.Count; // Replica number is max 2
                        // send replica to all successors
                        for (int i = 0; i < numberReplicas; i++)
                        {
                            NodeId successorNode = m_topology.routing_table.Successors[i];
                            ReloadMessage replica = create_store_req(new Destination(successorNode), storeRequest.ResourceId, recStoreKindData, true);
                            send(replica, m_topology.routing_table.GetNode(successorNode));
                        }
                    }
                }
                else
                {
                    // Signature over data in Store Request was invalid. Respond with Error Message!
                    send(create_erro_reply(new Destination(recmsg.OriginatorID), RELOAD_ErrorCode.Error_Forbidden, "Invalid Data Signature", ++m_ReloadConfig.TransactionID),
                      m_topology.routing_table.GetNode(recmsg.LastHopNodeId));
                }

            }
            // its a StoreAns
            else
            {
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TOPO, String.Format("Received StoreAns from: {0}", recmsg.OriginatorID));
                /*  ...this allows the storing peer to independently verify that the replicas have in fact been stored.
                 *  Note that the storing peer is not require to perform this verification.
                 *  see RELOAD base -12 p.91
                 */
            }

        }
Ejemplo n.º 29
0
        public IEnumerator<ITask> Send(Node node, ReloadMessage reloadMessage)  // node is remote peer
        {
            ReloadConnectionTableEntry connectionTableEntry = null;
            List<Byte[]> ByteArrayList = new List<byte[]>();
            ByteArrayList.Add(reloadMessage.ToBytes());
            //if (ReloadGlobals.FRAGMENTATION == true) {
            if (reloadMessage.forwarding_header.length > ReloadGlobals.MAX_PACKET_BUFFER_SIZE * ReloadGlobals.MAX_PACKETS_PER_RECEIVE_LOOP)
            {
                if (ByteArrayList[0].Length > ReloadGlobals.FRAGMENT_SIZE)
                { //TODO: fragment size should not be fix
                    ByteArrayList.Clear();
                    ByteArrayList = reloadMessage.ToBytesFragmented(ReloadGlobals.FRAGMENT_SIZE);
                }
            }
            
            foreach (byte[] ByteArray in ByteArrayList)
            {
                /* Try to find a matching connection using node id or target address*/
                if (node.Id != null)
                {
                    connectionTableEntry = connectionTable.lookupEntry(node.Id);
                    if (connectionTableEntry != null)
                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_SOCKET, String.Format("FLM: Found open connection for target node id {0}", node.Id));
                }
                if (connectionTableEntry == null)
                {
                    // connectionTableEntry == null   => no connection to remote peer
                    List<IceCandidate> icecandidates = node.IceCandidates;    // remote peer candidates
                    if (icecandidates != null)
                    {
                        foreach (IceCandidate candidate in icecandidates)
                        {
                            switch (candidate.addr_port.type)
                            {
                                case AddressType.IPv6_Address:
                                case AddressType.IPv4_Address:
                                    {
                                        ReloadSendParameters send_params;

                                        // check if there is already a attempt to open a connection to this node
                                        //if (connectionQueue.ContainsKey(candidate.addr_port))
                                        if (connectionQueue.ContainsKey(candidate))
                                        {
                                            // here we have a connection attempt
                                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING, String.Format("Connection Pending!!!!!!!!!!!!!!!!!!!!!!!!!!!"));
                                            //send_params = connectionQueue[candidate.addr_port];
                                            send_params = connectionQueue[candidate];
                                            yield return Arbiter.Receive(false, send_params.done, x => { });
                                            send_params.done.Post(true); //maybe there are still some other pending connections?

                                            if (send_params.connectionTableEntry != null)   //do we have a valid connection?
                                            {
                                                // here we have a valid connection
                                                connectionTableEntry = send_params.connectionTableEntry;
                                                if (send_params.connectionTableEntry.NodeID != null)        //TODO: correct?
                                                    node.Id = send_params.connectionTableEntry.NodeID;

                                                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING, String.Format("DONE!!!!!!!!!!!!!!!!!!!!!!!!!!!"));
                                                //connectionQueue.Remove(candidate.addr_port);
                                                connectionQueue.Remove(candidate);

                                                if (node.Id != null)
                                                {
                                                    connectionTableEntry = connectionTable.lookupEntry(node.Id);
                                                    if (connectionTableEntry != null)
                                                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_SOCKET, String.Format("FLM: Found open connection for target node id {0}", node.Id));

                                                    send_params = new ReloadSendParameters()
                                                    {
                                                        connectionTableEntry = connectionTableEntry,
                                                        destinationAddress = null,
                                                        port = 0,
                                                        buffer = ByteArray,
                                                        frame = true,
                                                        done = new Port<bool>(),
                                                        // markus
                                                        connectionSocket = null,
                                                    };

                                                    yield return Arbiter.ExecuteToCompletion(m_DispatcherQueue, new IterativeTask<Node, ReloadSendParameters>(node, send_params, link.Send));     // SEND
                                                    break;
                                                }
                                            }
                                            // here we have no valid connection, but a connection attempt (maybe break?)
                                            //break;    // markus
                                        }
                                        // no connection attempt (maybe else here?)
                                        // here is no existing connection and no attempt => try to connect

                                        // NO ICE or ICE but bootstrap
                                        if (ReloadGlobals.UseNoIce || candidate.cand_type == CandType.tcp_bootstrap)
                                        {
                                            connectionTableEntry = connectionTable.lookupEntry(new IPEndPoint(candidate.addr_port.ipaddr, candidate.addr_port.port));
                                            if (connectionTableEntry != null)
                                                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TRANSPORT, String.Format("FLM: Found open connection for target IP {0}:{1}", candidate.addr_port.ipaddr, candidate.addr_port.port));
                                            else
                                                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TRANSPORT, String.Format("Opening connection to {0}:{1}", candidate.addr_port.ipaddr, candidate.addr_port.port));

                                            send_params = new ReloadSendParameters()
                                            {

                                                connectionTableEntry = connectionTableEntry,
                                                destinationAddress = candidate.addr_port.ipaddr,
                                                port = candidate.addr_port.port,
                                                buffer = ByteArray,
                                                frame = true,
                                                done = new Port<bool>(),
                                                // markus
                                                connectionSocket = null,
                                            };

                                            //send_params.done.Post(false);

                                            //connectionQueue[candidate.addr_port] = send_params;
                                            connectionQueue[candidate] = send_params;
                                            //m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("Insert {0}:{1} into connectionQueue", new IPAddress(send_params.destinationAddress.Address).ToString(), send_params.port));

                                            yield return Arbiter.ExecuteToCompletion(m_DispatcherQueue, new IterativeTask<Node, ReloadSendParameters>(node, send_params, link.Send));   // SEND

                                            //connectionQueue.Remove(candidate.addr_port);
                                            connectionQueue.Remove(candidate);
                                            if (send_params.connectionTableEntry != null)
                                            {
                                                connectionTableEntry = send_params.connectionTableEntry; //TODO: not nice but does the trick
                                                if (send_params.connectionTableEntry.NodeID != null)        //TODO: correct?
                                                    node.Id = send_params.connectionTableEntry.NodeID;
                                            }
                                        }

                                        // ICE peer
                                        //else
                                        //{

                                        //    connectionTableEntry = connectionTable.lookupEntry(new IPEndPoint(candidate.addr_port.ipaddr, candidate.addr_port.port));
                                        //    if (connectionTableEntry != null)
                                        //        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TRANSPORT, String.Format("FLM: Found open connection for target IP {0}:{1}", candidate.addr_port.ipaddr, candidate.addr_port.port));
                                        //    else
                                        //        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_TRANSPORT, String.Format("Opening connection to {0}:{1}", candidate.addr_port.ipaddr, candidate.addr_port.port));


                                        //    // try to get connection
                                        //    Socket connectionSocket = null;
                                        //    m_connectionsToRemotePeer.TryGetValue(candidate.addr_port, out connectionSocket);
                                        //    //if (connectionSocket == null)
                                        //    //    continue;  //versuche mit nächsten candidate

                                        //    send_params = new ReloadSendParameters()
                                        //    {

                                        //        connectionTableEntry = connectionTableEntry,
                                        //        destinationAddress = candidate.addr_port.ipaddr,
                                        //        port = candidate.addr_port.port,
                                        //        buffer = ByteArray,
                                        //        frame = true,
                                        //        done = new Port<bool>(),
                                        //        // markus
                                        //        connectionSocket = connectionSocket,
                                        //    };

                                        //    //send_params.done.Post(false);

                                        //    connectionQueue[candidate.addr_port] = send_params;

                                        //    yield return Arbiter.ExecuteToCompletion(m_DispatcherQueue, new IterativeTask<Node, ReloadSendParameters>(node, send_params, link.Send));   // SEND

                                        //    connectionQueue.Remove(candidate.addr_port);
                                        //    if (send_params.connectionTableEntry != null)
                                        //    {
                                        //        connectionTableEntry = send_params.connectionTableEntry; //TODO: not nice but does the trick
                                        //        if (send_params.connectionTableEntry.NodeID != null)        //TODO: correct?
                                        //            node.Id = send_params.connectionTableEntry.NodeID;
                                        //    }
                                        //}

                                    }
                                    break;
                            }
                            //just support one ice candidate only here
                            break;
                        } // foreach ice candidate

                    }
                }
                else
                {
                    // connectionTableEntry != null   => existing connection to remote peer
                    ReloadSendParameters send_params = new ReloadSendParameters()
                    {
                        connectionTableEntry = connectionTableEntry,
                        destinationAddress = null,
                        port = 0,
                        buffer = ByteArray,
                        frame = true,
                        done = new Port<bool>(),
                    };

                    yield return Arbiter.ExecuteToCompletion(m_DispatcherQueue, new IterativeTask<Node, ReloadSendParameters>(node, send_params, link.Send));     // SEND
                }
            } // foreach ByteArray
            yield break;
        }   // Send
Ejemplo n.º 30
0
 public bool PutViaListToDestination(ReloadMessage rmDest)
 {
     if (forwarding_header.via_list != null)
     {
         forwarding_header.via_list.Remove(forwarding_header.via_list.First());
         //this function assumes that the final destination already set to destination list
         foreach (Destination dest in forwarding_header.via_list)
         {
             //using index 0 will actually reverse the via list items, which is required see "3.3. Routing"
             rmDest.forwarding_header.destination_list.Insert(0, dest);
         }
         forwarding_header.via_list.Clear();
     }
     return true;
 }