コード例 #1
0
ファイル: Topology.cs プロジェクト: RELOAD-NET/RELOAD.NET
 public Node GetNode(NodeId node_id) {
     RTableEntry rte;
     if (node_id == null)
         return null;
     m_RtTable.TryGetValue(node_id.ToString(), out rte);
     if (rte != null)
         return rte.node;
     else
         return new Node(node_id, GetCandidates(node_id));
 }
コード例 #2
0
ファイル: Topology.cs プロジェクト: RELOAD-NET/RELOAD.NET
            public bool GetPing(NodeId nodeid) {
                RTableEntry rtable;

                if (nodeid != null && m_RtTable.TryGetValue(nodeid.ToString(), out rtable)) {
                    return rtable.pinging;
                }
                return false;
            }
コード例 #3
0
ファイル: Topology.cs プロジェクト: RELOAD-NET/RELOAD.NET
            public bool IsWaitForJoinAnsw(NodeId nodeid) {
                RTableEntry rtable;

                if (nodeid != null && m_RtTable.TryGetValue(nodeid.ToString(), out rtable)) {
                    return rtable.wait_for_join_answ;
                }
                return false;
            }
コード例 #4
0
ファイル: Topology.cs プロジェクト: RELOAD-NET/RELOAD.NET
            /// <summary>
            /// Returns the ice candidates stored in a dicationary along with a nodeid
            /// </summary>
            /// <param name="nodeid">The Node Id</param>
            /// <returns>List<IceCandidate></returns>
            /// <summary>
            public List<IceCandidate> GetCandidates(NodeId nodeid) {
                RTableEntry rtable;

                if (nodeid != null && m_RtTable.TryGetValue(nodeid.ToString(), out rtable))
                    return rtable.icecandidates;
                return null;
            }
コード例 #5
0
ファイル: Topology.cs プロジェクト: RELOAD-NET/RELOAD.NET
            /// <summary>
            /// We need the information if a node (nodeid) has already been attached to
            /// and is valid. This is stored in the routing table
            /// </summary>
            /// <param name="nodeid">The Node Id</param>
            /// <returns>bool</returns>
            public NodeState GetNodeState(NodeId nodeid) {
                RTableEntry rtable;

                if (nodeid != null && m_RtTable.TryGetValue(nodeid.ToString(), out rtable)) {
                    return rtable.nodestate;
                }
                return NodeState.unknown;
            }
コード例 #6
0
ファイル: Topology.cs プロジェクト: RELOAD-NET/RELOAD.NET
            internal void SetPinging(NodeId nodeId, bool ping, bool success) {
                try {
                    RTableEntry rtable_entry;

                    lock (m_RtTable) {
                        if (nodeId != null && m_RtTable.TryGetValue(nodeId.ToString(), out rtable_entry)) {
                            rtable_entry.pinging = ping;
                            if (success)
                                rtable_entry.dtLastSuccessfullPing = DateTime.Now;
                        }
                    }
                }
                catch (Exception ex) {
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "SetPinging: " + ex.Message);
                }
            }
コード例 #7
0
ファイル: Topology.cs プロジェクト: RELOAD-NET/RELOAD.NET
            internal void SetWaitForJoinAnsw(NodeId nodeId, Boolean fTrue) {
                try {
                    RTableEntry rtable_entry;

                    lock (m_RtTable) {
                        if (nodeId != null && m_RtTable.TryGetValue(nodeId.ToString(), out rtable_entry))
                            rtable_entry.wait_for_join_answ = fTrue;
                    }
                }
                catch (Exception ex) {
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "SetWaitForJoinAnsw: " + ex.Message);
                }
            }
コード例 #8
0
ファイル: Topology.cs プロジェクト: RELOAD-NET/RELOAD.NET
            internal void SetNodeState(NodeId nodeId, NodeState nodestate) {
                try {
                    RTableEntry rtable;

                    lock (m_RtTable) {
                        if (nodeId != null && m_RtTable.TryGetValue(nodeId.ToString(), out rtable)) {
                            NodeState oldstate = rtable.nodestate;

                            switch (rtable.nodestate) {
                                case NodeState.unknown:
                                    rtable.nodestate = nodestate;
                                    break;
                                case NodeState.attaching:
                                    rtable.nodestate = nodestate;
                                    break;
                                case NodeState.attached:
                                    if (nodestate == NodeState.attaching) {
                                        //m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "SetNodeState: invalid transition from attached to attaching");
                                        //ignore, should only occur on AppAttach
                                    }
                                    else {
                                        if (nodestate == NodeState.attached & m_UpdateReceivedFromUnattachedNode.Contains(nodeId)) {
                                            m_UpdateReceivedFromUnattachedNode.Remove(nodeId);
                                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, "SetNodeState: attached -> updates_received on saved state");
                                            rtable.nodestate = NodeState.updates_received;

                                        }
                                        else
                                            rtable.nodestate = nodestate;
                                    }
                                    break;
                                case NodeState.updates_received:
                                    //ignore attach messages here
                                    if (nodestate != NodeState.attached && nodestate != NodeState.attaching)
                                        rtable.nodestate = nodestate;
                                    break;
                            }

                            if (m_ReloadConfig.State == ReloadConfig.RELOAD_State.Joined
                                && (nodestate == NodeState.attached || rtable.nodestate == NodeState.updates_received)
                                && (oldstate == NodeState.attaching || oldstate == NodeState.unknown)) {
                                if (m_predecessors.Contains(nodeId) || m_successors.Contains(nodeId)) {
                                    /* A not approved node stored in successor and predecessor list became valid (attached).
                                     * This is a trigger to send an update to all (valid) neighbors
                                     */
                                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_BUG, String.Format("AddNode: New approved neighbor, send updates to all"));
                                    SendUpdateToAllNeighbors();
                                }
                            }
                        }
                        else {
                            if (nodestate == NodeState.updates_received) {
                                /* bad situation, we received an update but probably no attach answ so far
                                 * save this info for later use */
                                m_UpdateReceivedFromUnattachedNode.Add(nodeId);
                            }
                        }
                    }
                }
                catch (Exception ex) {
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "SetNodeState: " + ex.Message);
                }
            }
コード例 #9
0
ファイル: Topology.cs プロジェクト: RELOAD-NET/RELOAD.NET
            public bool Leave(NodeId nodeId) {
                /* 
                 * A node leaves the overlay, do we have to notify the neighbors?
                 * (Which is the case if this node was part of our lists)
                 */
                bool fUpdateNeeded = false;
                bool fWasAdmittingPeer = false;
                bool fEvaluateReplicas = false;

                SetNodeState(nodeId, NodeState.unknown);

                if (m_ReloadConfig.AdmittingPeer != null && m_ReloadConfig.AdmittingPeer.Id != null)
                    if (nodeId == m_ReloadConfig.AdmittingPeer.Id) {
                        m_ReloadConfig.AdmittingPeer = null;
                        fWasAdmittingPeer = true;
                    }

                if (m_successors.Contains(nodeId)) {
                    int index = m_successors.IndexOf(nodeId);

                    m_successors.Remove(nodeId);
                    // Leaving nodes will be stored for 5 minutes to make sure we do not learn about them again
                    AddLeavingNode(nodeId);
                    fUpdateNeeded = true;
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ALL, String.Format("Deleted {0} from Successors", nodeId));

                    // Has Successor 1 or 2 crashed? Do we need to send out a new store request for replicas?
                    if (index < 2 && m_successors.Count > 1)
                        Arbiter.Activate(m_ReloadConfig.DispatcherQueue, new IterativeTask<NodeId>(m_successors[1], m_transport.StoreReplicas));
                }

                if (m_predecessors.Contains(nodeId)) {
                    int index = m_predecessors.IndexOf(nodeId);
                    if (index == 0)
                        fEvaluateReplicas = true;

                    m_predecessors.Remove(nodeId);
                    AddLeavingNode(nodeId);
                    fUpdateNeeded = true;
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ALL, String.Format("Deleted {0} from Predecessors", nodeId));

                    if (fEvaluateReplicas == true)
                        m_transport.EvaluateReplicas();
                }

                foreach (FTableEntry fte in FingerTable)
                    if (fte.Successor == nodeId) {
                        fte.Successor = null;
                        fte.valid = false;
                    }

                if (m_RtTable.ContainsKey(nodeId.ToString()))
                {
                    m_RtTable.Remove(nodeId.ToString());
                    AddLeavingNode(nodeId);
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ALL, String.Format("Deleted {0} from Routing Table", nodeId));
                    fUpdateNeeded = true;
                }

                if (fUpdateNeeded && !m_ReloadConfig.IamClient) {
                    SendUpdateToAllNeighbors();
                }

                if (fWasAdmittingPeer) {
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING, String.Format("Lost admitting peer {0}: starting prejoin procedure", nodeId));
                    Arbiter.Activate(m_DispatcherQueue, new IterativeTask<List<BootstrapServer>>(m_ReloadConfig.ThisMachine.BootstrapServer, m_ReloadConfig.ThisMachine.Transport.PreJoinProdecure));
                }
                return fWasAdmittingPeer;
            }
コード例 #10
0
ファイル: Simple.cs プロジェクト: RELOAD-NET/RELOAD.NET
    private IEnumerator<ITask> Receive(Socket socketClient, NodeId nodeid) {
      if (socketClient == null) {
        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("SimpleFLM: Receive: socket == null!!!"));
        yield break;
      }

      if (!socketClient.Connected) {
        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("SimpleFLM: << {0} receive, but client is not connected", socketClient.RemoteEndPoint));
        HandleRemoteClosing(socketClient);
        yield break;
      }

      while (socketClient != null && m_ReloadConfig.State < ReloadConfig.RELOAD_State.Exit) {
        byte[] buffer = new byte[ReloadGlobals.MAX_PACKET_BUFFER_SIZE * ReloadGlobals.MAX_PACKETS_PER_RECEIVE_LOOP];

        var iarPort = new Port<IAsyncResult>();
        int bytesReceived = 0;

        try {
          m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_SOCKET, String.Format("SimpleFLM: << {0} BeginReceive", socketClient == null ? "null" : socketClient.RemoteEndPoint.ToString()));
          socketClient.BeginReceive(
              buffer,
              0,
              buffer.Length,
              SocketFlags.None, iarPort.Post, null);
        }
        catch (Exception ex) {
          m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("SimpleFLM: << {0} BeginReceive", socketClient == null ? "null" : socketClient.RemoteEndPoint.ToString()) + ex.Message);
        }
        yield return Arbiter.Receive(false, iarPort, iar => {
          try {
            if (iar != null)
              bytesReceived = socketClient.EndReceive(iar);
          }
          catch (Exception ex) {
            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO,
              String.Format("SimpleFLM: << {0} Receive: {1} ",
              nodeid == null ? "" : nodeid.ToString(), ex.Message));
          }

          if (bytesReceived <= 0) {
            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_SOCKET, 
              String.Format("SimpleFLM: << {0} Receive: lost connection, closing socket",
              socketClient.RemoteEndPoint));
            HandleRemoteClosing(socketClient);
            socketClient.Close();
            socketClient = null;
            return;
          }

          m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_SOCKET,
            String.Format("SimpleFLM: << {0} Read {1} bytes from {2}",
            socketClient.RemoteEndPoint, 
            bytesReceived, nodeid == null ? "" : nodeid.ToString()));

          m_ReloadConfig.Statistics.BytesRx = (UInt64)bytesReceived;

#if CONNECTION_MANAGEMENT
          /* beginn connection management */
          long bytesProcessed = 0;
          SimpleOverlayConnectionTableElement socte = null;

          if (ReloadGlobals.Framing) {
            foreach (KeyValuePair<string, SimpleOverlayConnectionTableElement> pair in m_connection_table) {
              if (socketClient == pair.Value.AssociatedSocket) {
                socte = pair.Value;
                break;
              }
            }

            if (socte == null)
              socte = new SimpleOverlayConnectionTableElement();
            Array.Resize(ref buffer, bytesReceived);
            buffer = analyseFrameHeader(socte, buffer);
            bytesReceived = buffer.Length;
          }

          ReloadMessage reloadMsg = null;

          if (buffer != null) {
            reloadMsg = new ReloadMessage(m_ReloadConfig).FromBytes(buffer,
              ref bytesProcessed, ReloadMessage.ReadFlags.full);
          }

          if (socketClient != null && reloadMsg != null) {
            if (nodeid == null)
              nodeid = reloadMsg.LastHopNodeId;

            if (nodeid != null)
              if (m_connection_table.ContainsKey(nodeid.ToString())) {
                SimpleOverlayConnectionTableElement rcel = m_connection_table[
                  nodeid.ToString()];
                rcel.LastActivity = DateTime.Now;
              }
              else {
                SimpleOverlayConnectionTableElement rcel = socte;
                if (rcel == null)
                  rcel = new SimpleOverlayConnectionTableElement();
                rcel.NodeID = reloadMsg.LastHopNodeId;
                rcel.AssociatedSocket = socketClient;
                /*
                 * tricky: if this is an answer, this must be issued by an 
                 * outgoing request before (probably the first 
                 * bootstrap contact, where we have no nodeid from)
                 */
                rcel.Outbound = !reloadMsg.IsRequest();
                rcel.LastActivity = rcel.Start = DateTime.Now;

                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_SOCKET,
                  String.Format("SimpleFLM: << {0} Receive: Associating node {1}",
                  socketClient.RemoteEndPoint, rcel.NodeID.ToString()));
                lock (m_connection_table) {
                  if (nodeid != m_ReloadConfig.LocalNodeID) {
                    if (!m_connection_table.ContainsKey(rcel.NodeID.ToString()))
                      m_connection_table.Add(rcel.NodeID.ToString(), rcel);
                    else
                      m_connection_table[rcel.NodeID.ToString()] = rcel;
                  }
                }
              }
            /* end connection management */

            if (ReloadFLMEventHandler != null) {
              //there might by more then one packet inside
              m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_SOCKET,
                String.Format("SimpleFLM: << {0} <== {1} {2}, TransID={3:x16}", socketClient.RemoteEndPoint, reloadMsg.reload_message_body.RELOAD_MsgCode.ToString(), nodeid.ToString(), reloadMsg.TransactionID));


              ReloadFLMEventHandler(this, new ReloadFLMEventArgs(
                ReloadFLMEventArgs.ReloadFLMEventTypes.RELOAD_EVENT_RECEIVE_OK,
                null, reloadMsg));

              if (bytesProcessed != bytesReceived) {
                long bytesProcessedTotal = 0;
                string lastMsgType = "";
                while (reloadMsg != null
                  && bytesProcessedTotal < bytesReceived) {
                  //in - offset out - bytesprocessed
                  bytesProcessed = bytesProcessedTotal;
                  //TKTODO add framing handling  here
                  reloadMsg = new ReloadMessage(m_ReloadConfig).FromBytes(
                    buffer, ref bytesProcessed, ReloadMessage.ReadFlags.full);
                  // Massive HACK!!! offset of TCP messages is set wrong TODO!!!
                  int offset = 0;
                  while (reloadMsg == null) {
                    offset++;
                    bytesProcessedTotal++;
                    bytesProcessed = bytesProcessedTotal;
                    reloadMsg = new ReloadMessage(m_ReloadConfig).FromBytes(
                      buffer, ref bytesProcessed, ReloadMessage.ReadFlags.full);
                    if (reloadMsg != null)
                      m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                        String.Format("Last message type: {0}, offset: {1}",
                        lastMsgType, offset));
                  }
                  ReloadFLMEventHandler(this, new ReloadFLMEventArgs(
                    ReloadFLMEventArgs.ReloadFLMEventTypes.RELOAD_EVENT_RECEIVE_OK,
                    null, reloadMsg));
                  m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_SOCKET,
                      String.Format("SimpleFLM: << {0} <== {1} {2}, TransID={3:x16}",
                      socketClient.RemoteEndPoint,
                      reloadMsg.reload_message_body.RELOAD_MsgCode.ToString(),
                      nodeid.ToString(),
                      reloadMsg.TransactionID));
                  bytesProcessedTotal += bytesProcessed;                  
                  lastMsgType = reloadMsg.reload_message_body.RELOAD_MsgCode.ToString();
                }
              }
            }
          }
          else {
            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
              String.Format("SimpleFLM: << {0} Receive: Dropping invalid packet,"+
              "bytes received: {1}", socketClient.RemoteEndPoint, bytesReceived));
          }
#endif
#if !CONNECTION_MANAGEMENT
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_SOCKET, String.Format("SimpleFLM: << {0} Receive: Closing socket", client.RemoteEndPoint));
                    if(client.Connected)
                        client.Shutdown(SocketShutdown.Both);
                    client.Close();
#endif
        });
      }
    }
コード例 #11
0
ファイル: ReDiR.cs プロジェクト: RELOAD-NET/RELOAD.NET
    private int responsibleNodeByLevel(int level, NodeId id)    //TODO:DONE?!
    {
      NodeId max = new NodeId();
      max = max.Max();
      NodeId upperbound = new NodeId();
      upperbound = upperbound.Min();

      int i = 0;

      do {
        //if (level == 0)
        //  break; //only one node at level 0

        NodeId temp = (max) >> (level);
        upperbound = upperbound + ((temp)) + 1;

        if (id < upperbound || upperbound==(new NodeId()).Min())//upperbound==(new NodeId()).Min() for level 0 and last node at level where upperbound overflows to 0
          break;

        i++;
      } while (upperbound.Data[0] != 0x00);

      machine.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, String.Format("REDIR: NodeId: " + id.ToString() + " Level: " + level + " => upper bound:  " + upperbound.ToString() + " Node: " + i));
      return i;

    }
コード例 #12
0
ファイル: ReDiR.cs プロジェクト: RELOAD-NET/RELOAD.NET
    private void deliverResult(ResourceId resid, string nameSpace, NodeId id) {      

      if (nameSpace == null) {
        if (ReDiRLookupFailed != null)
          ReDiRLookupFailed(m_nameSpace);
        machine.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, "ReDiR: No Result for " + resid);
      }
      else {
        if ( ReDiRLookupCompleted != null)
          ReDiRLookupCompleted(nameSpace, id);
        machine.ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_REDIR, "ReDiR: Result for " + resid + " : nameSpace=" + nameSpace + "ID=" + id.ToString());
      }

    }