Esempio n. 1
0
        public ReloadDialog(ReloadConfig reloadConfig, IForwardLinkManagement transport, Node nexthopnode) {
            this.m_NextHopNode = nexthopnode;
            this.m_Transport = transport;
            this.m_fDone = new Port<bool>();
            this.m_DispatcherQueue = reloadConfig.DispatcherQueue;
            this.m_ReloadConfig = reloadConfig;
            m_Transport.ReloadFLMEventHandler += new ReloadFLMEvent(OVL_ReloadForwardLinkManagementEventHandler);

            if(nexthopnode.IceCandidates == null)
                throw new System.Exception(String.Format("ReloadDialog: no ice candidates for {0} ", nexthopnode.Id));
        }
Esempio n. 2
0
        public InitInput Validate()
        {
            try
            {
                CacheConfig.ThrowIfNull($"{nameof(CacheConfig)}");
                if (CacheConfig.AdType == AdditionalData.Database)
                {
                    AdditionalDataConnectionMgr.ThrowIfNull($"{nameof(AdditionalDataConnectionMgr)}");
                }
                ReloadConfig.ThrowIfNull($"{nameof(ReloadConfig)}");
                SerializationConfig.ThrowIfNull($"{nameof(SerializationConfig)}");
                TopLevelLocalDirectory.ThrowIfNullOrNonExisting($"{nameof(TopLevelLocalDirectory)}");
                ActualDataConnectionMgr.ThrowIfNull($"{nameof(ActualDataConnectionMgr)}");
                Logger.ThrowIfNull($"{nameof(Logger)}");

                return(this);
            }
            catch (ArgumentException e)
            {
                throw new AsyncCacheException(AsyncCacheErrorCode.InvalidConfig, "Some config is invalid", e);
            }
        }
Esempio n. 3
0
 public ReloadConfigResolve(ReloadConfig reloadConfig) {
   m_ReloadConfig = reloadConfig;
 }
Esempio n. 4
0
    /// <summary>
    /// Each StoredData element is individually signed.  However, the
    /// signature also must be self-contained and cover the Kind-ID and
    /// Resource-ID even though they are not present in the StoredData
    /// structure.  The input to the signature algorithm is:
    /// resource_id || kind || storage_time || StoredDataValue ||
    /// SignerIdentity
    /// </summary>
    /// <param name="resId"></param>
    /// <param name="kind"></param>
    /// <param name="storageTime"></param>
    /// <param name="storedDataValue"></param>
    /// <param name="identity"></param>
    public Signature(ResourceId resId, UInt32 kind, UInt64 storageTime,
      StoredDataValue value, SignerIdentity signerIdentity,
      ReloadConfig config) {

      m_ReloadConfig = config;
      var ascii = new ASCIIEncoding();
      /* Set alogorithm and identity */
      algorithm =  new SignatureAndHashAlgorithm(HashAlgorithm.sha256,
        ReloadGlobals.SignatureAlg);
      identity = signerIdentity;
      /* Get string of stored data value */
      var ms = new MemoryStream();
      var bw = new BinaryWriter(ms);
      value.Dump(bw);
      value.GetUsageValue.dump(bw);
      ms.Position = 0;
      var sr = new StreamReader(ms);
      string strValue = sr.ReadToEnd();
      sr.Close();
      bw.Close();
      /* Concatenate signature input */
      String signaturInput = String.Format("{0}{1}{2}{3}{4}",
        ascii.GetString(resId.Data, 0, resId.Data.Length), kind, storageTime,
        strValue, identity.ToString());
      signatureValue = Sign(signaturInput);
    }
Esempio n. 5
0
    /// <summary>
    /// For signatures over messages the input to the signature is computed
    /// over the overlay and transaction_id come from the forwarding header
    /// see RELOAD base -13 p.53
    /// </summary>
    /// <param name="overlay">overlay</param>
    /// <param name="transaction_id">transaction_id</param>
    /// <param name="messageContents">Message Contents</param>
    /// <param name="signerIdentity">SignerIdentity</param>
    public Signature(UInt32 overlay, string transactionId, string messageContents, SignerIdentity signerIdentity, ReloadConfig config) {

      m_ReloadConfig = config;

      algorithm = new SignatureAndHashAlgorithm(HashAlgorithm.sha256,
        ReloadGlobals.SignatureAlg);
      identity = signerIdentity;
      /* Compute signature */      
      String signaturInput = String.Format("{0}{1}{2}{3}", overlay, transactionId, messageContents, identity.ToString());

      signatureValue = Sign(signaturInput);      
    }
Esempio n. 6
0
 /// <summary>
 /// Computes the signature of the stored data.
 /// The input to the signature algorithm is:
 ///
 /// resource_id || kind || storage_time || StoredDataValue ||
 /// SignerIdentity
 /// Where || indicates concatenation.
 /// </summary>
 /// <param name="resId"></param>
 /// <param name="kindId"></param>
 public void SignData(ResourceId resId, UInt32 kindId, SignerIdentity id,
   ReloadConfig rc) {
     signature = new Signature(resId, kindId, storage_time,
       value, id, rc);
 }
Esempio n. 7
0
 public SimpleOverlayLink(ReloadConfig reloadConfig) {
   m_ReloadConfig = reloadConfig;
 }
Esempio n. 8
0
 public TopologyPlugin(Machine machine) {
     m_id = machine.ReloadConfig.LocalNodeID;
     m_transport = machine.Transport;
     m_DispatcherQueue = machine.ReloadConfig.DispatcherQueue;
     m_ReloadConfig = machine.ReloadConfig;
     storage = new StorageModul(m_ReloadConfig);
 }
Esempio n. 9
0
    public AccessController(ReloadConfig rc) {
      var ascii = new ASCIIEncoding();
      m_ReloadConfig = rc;
      storedPKCs = new Dictionary<string, GenericCertificate>();
      ACPs = new Dictionary<String, IAccessControlPolicy>();
      ACPmap = new Dictionary<UInt32, String>();
      /* Convert My TEIX509Certificate to opaque string*/
      /* SignerIdValue*/
      var sha256 = new SHA256Managed();
      byte[] myCert;
      //m_ReloadConfig.MyCertificate.SaveToBuffer(out myCert);
      //myCert = m_ReloadConfig.MySSLCertificate.DER;
      myCert = m_ReloadConfig.MyCertificate.GetRawCertData();
      byte[] bHash = sha256.ComputeHash(myCert);
      var signIdVal = new SignerIdentityValue(SignerIdentityType.cert_hash,
        ReloadGlobals.HashAlg, bHash);

      /* Publish my Id and my PKC */
      var myGenCert = new GenericCertificate(myCert);
      myIdentity = new SignerIdentity(SignerIdentityType.cert_hash, signIdVal);
      string strHash = String.Join(String.Empty, bHash.Select(b => b.ToString("x2")));
      storedPKCs.Add(strHash, myGenCert);
    }
Esempio n. 10
0
 public SimpleFLM(ReloadConfig reloadConfig) {
   m_ReloadConfig = reloadConfig;
   m_statistics = reloadConfig.Statistics;
   link = new SimpleOverlayLink(reloadConfig);
   link.ReloadFLMEventHandler += new ReloadFLMEvent(link_ReloadFLMEventHandler);
 }
Esempio n. 11
0
 private void onStateUpdate(ReloadConfig.RELOAD_State state) {
 }
Esempio n. 12
0
    public Machine() {
      m_ReloadConfig = new ReloadConfig(this);

      m_UsageManager = new UsageManager();

      gatheredSpecifiers = new List<StoredDataSpecifier>();

      gatheredStoreDatas = new List<StoreKindData>();
	  
	  gatheredSpecifiersQueue = new Port<List<StoredDataSpecifier>>();

    gatheredStoreDatasQueue = new Port<List<StoreKindData>>();

	  storeViaGateway = new Dictionary<List<StoreKindData>, NodeId>();

	  fetchViaGateway = new Dictionary<List<StoredDataSpecifier>, NodeId>();

    }
Esempio n. 13
0
 public StorageModul(ReloadConfig config) {
   s_ReloadConfig = config;
   resources = new Dictionary<string, Resource>();
 }
Esempio n. 14
0
        private static void PeformCheck(CandidatePair candPair, ReloadConfig.LogHandler logger)
        {
            // local active candidate
            if (candPair.localCandidate.tcpType == TcpType.Active)
            {
                // try to connect to remote candidate
                try
                {
                    //Socket connectingSocket = candPair.localCandidate.activeConnectingSocket;
                    IPEndPoint localEndPoint = new IPEndPoint(candPair.localCandidate.addr_port.ipaddr, candPair.localCandidate.addr_port.port);
                    Socket connectingSocket = null;

                    int retry = CONNECT_RETRIES;
                    while (retry > 0)
                    {
                        logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("PerformCheck connect to {0}:{1} retry {2}", candPair.remoteCandidate.addr_port.ipaddr.ToString(),
                            candPair.remoteCandidate.addr_port.port, retry));
                        connectingSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        connectingSocket.Bind(localEndPoint);

                        TimeoutSocket.Connect(connectingSocket, new IPEndPoint(candPair.remoteCandidate.addr_port.ipaddr, candPair.remoteCandidate.addr_port.port), ICE.SOCKET_TIMEOUT / CONNECT_RETRIES);
                        if (connectingSocket.Connected)
                            break;
                        retry--;
                    }

                    // connected?
                    if (connectingSocket.Connected)
                    {
                        // TEST: save connected socket
                        candPair.localCandidate.activeConnectingSocket = connectingSocket;
                        // TODO: send stun checks

                        // if stun check is successfull set state to succeeded
                        candPair.state = CandidatePairState.Succeeded;
                    }
                    else
                    {
                        candPair.state = CandidatePairState.Failed;
                    }
                }
                catch (Exception e)
                {
                    //Console.WriteLine(e.Message);

                    /* RFC 6544, ICE-TCP, Section 7.1:
                    If the TCP connection cannot be established, the check is considered
                    to have failed, and a full-mode agent MUST update the pair state to
                    Failed in the check list
                    */
                    candPair.state = CandidatePairState.Failed;
                }

            }

            // local passive candidate
            else if (candPair.localCandidate.tcpType == TcpType.Passive)
            {
                // try to accept a connection on listening port from remote peer
                try
                {
                    Socket listeningSocket = candPair.localCandidate.passiveListeningSocket;
                    listeningSocket.Listen(10);

                    logger(ReloadGlobals.TRACEFLAGS.T_INFO, String.Format("PerformCheck listen to {0}:{1}", ((IPEndPoint)listeningSocket.LocalEndPoint).Address.ToString(),
                        ((IPEndPoint)listeningSocket.LocalEndPoint).Port));

                    //Socket acceptedSocket = candPair.localCandidate.passiveAcceptedSocket;
                    candPair.localCandidate.passiveAcceptedSocket = TimeoutSocket.Accept(listeningSocket, ICE.SOCKET_TIMEOUT);

                    // connection accepted?
                    if (candPair.localCandidate.passiveAcceptedSocket != null && candPair.localCandidate.passiveAcceptedSocket.Connected)
                    {
                        // TODO: send stun checks

                        // if stun check is successfull set state to succeeded
                        candPair.state = CandidatePairState.Succeeded;
                    }
                    else
                    {
                        candPair.state = CandidatePairState.Failed;
                    }
                }
                catch (Exception e)
                {
                    candPair.state = CandidatePairState.Failed;
                }
            }

            // local so candidate
            else if (candPair.localCandidate.tcpType == TcpType.SO)
            {
                // try to connect to remote candidate and to accept a connection on listening port from remote peer
                try
                {
                    Socket connectingSocket = candPair.localCandidate.soConnectingSocket;
                    Socket listeningSocket = candPair.localCandidate.soListeningSocket;
                    listeningSocket.Listen(10);

                    // run Accept and Connect simultaneously
                    Socket acceptedSocket = candPair.localCandidate.soAcceptedSocket;
                    candPair.localCandidate.soAcceptedSocket = RunAcceptAndConnect(candPair, connectingSocket, listeningSocket);

                    if (connectingSocket.Connected || (acceptedSocket != null && acceptedSocket.Connected))
                    {
                        // TODO: send stun checks

                        // if stun check is successfull set state to succeeded
                        candPair.state = CandidatePairState.Succeeded;
                    }
                    else
                    {
                        candPair.state = CandidatePairState.Failed;
                    }

                }
                catch (Exception e)
                {
                    candPair.state = CandidatePairState.Failed;
                }
            }

        }
Esempio n. 15
0
 /// <summary>
 /// Default constructor. Use it as receiver of a request.
 /// </summary>
 public SecurityBlock(ReloadConfig rc)
 {
     m_ReloadConfig = rc;
     m_AccessControl = rc.AccessController;
     certificates = new List<GenericCertificate>();
 }
Esempio n. 16
0
 /// <summary>
 /// Inits the Usage Manager.
 /// </summary>
 /// <param name="machine">The state machine for RELOAD overlay.</param>
 public void Init(Machine machine) {
   localNode = machine.Topology.LocalNode;
   m_Transport = machine.Transport;
   m_ReloadConfig = machine.ReloadConfig;
   m_DispatcherQueue = machine.ReloadConfig.DispatcherQueue;
   usages = new Dictionary<Usage_Code_Point, IUsage>();
   m_ArrayManager = new ArrayManager();
 }
Esempio n. 17
0
 /// <summary>
 /// Creates a new Security Block for ordinary messages
 /// </summary>
 /// <param name="signerCert">X.509 PKC of the request originator</param>
 public SecurityBlock(ReloadConfig rc, SignerIdentity myIdentity)
 {
     m_ReloadConfig = rc;
     m_AccessControl = rc.AccessController;
     /* Add the certificate of signer */
     certificates = new List<GenericCertificate>();
     GenericCertificate myCert = m_AccessControl.GetPKC(myIdentity);
     certificates.Add(myCert);
     signerId = myIdentity;
 }
Esempio n. 18
0
            public RoutingTable(Node local_node, Machine machine) {
                m_ReloadConfig = machine.ReloadConfig;
                m_flm = machine.Interface_flm;
                m_DispatcherQueue = machine.ReloadConfig.DispatcherQueue;
                m_transport = machine.Transport;
                m_local_node = local_node;
                m_successors = new List<NodeId>();
                m_predecessors = new List<NodeId>();
                m_fingerSuccessors = new List<NodeId>();

                for (int i = 0; i < 128; i++)
                    m_FingerTable.Add(new FTableEntry()
                    {
                        Finger = new ResourceId(local_node.Id + ReloadGlobals.BigIntPow2Array[i]),
                        dtLastSuccessfullFinger = DateTime.MinValue,
                        nodestate = NodeState.unknown
                    });

                /* 
                   A peer MUST NOT enter
                   itself in its successor or predecessor table and instead should leave
                   the entries empty.
                 */
            }
Esempio n. 19
0
 /// <summary>
 /// Creates a new Security Block for data transporting messages
 /// </summary>
 /// <param name="signerCert">X.509 PKC of the request originator</param>
 /// <param name="certs">X.509 PKCs for validation data</param>
 public SecurityBlock(ReloadConfig rc, SignerIdentity myIdentity, List<byte[]> certs)
 {
     m_ReloadConfig = rc;
     m_AccessControl = rc.AccessController;
     /* Add the certificate of signer */
     certificates = new List<GenericCertificate>();
     GenericCertificate myCert = m_AccessControl.GetPKC(myIdentity);
     certificates.Add(myCert);
     /* Add all other PKCs */
     foreach (byte[] pkc in certs)
     {
         certificates.Add(new GenericCertificate(pkc));
     }
     signerId = myIdentity;
 }
Esempio n. 20
0
 public void Init(Machine machine)
 {
     m_machine = machine;
     m_topology = machine.Topology;
     m_forwarding = machine.Forwarding;
     m_flm = machine.Interface_flm;
     m_DispatcherQueue = machine.ReloadConfig.DispatcherQueue;
     m_ReloadConfig = machine.ReloadConfig;
     m_statistics = m_ReloadConfig.Statistics;
 }
Esempio n. 21
0
        public ReloadMessage(ReloadConfig rc, NodeId OriginatorNodeID,
          Destination destination, UInt64 trans_id, RELOAD_MessageBody reload_content)
        {
            m_ReloadConfig = rc;
            forwarding_header.version = ReloadGlobals.RELOAD_VERSION;
            forwarding_header.ttl = ReloadGlobals.TTL;
            forwarding_header.overlay = m_ReloadConfig.OverlayHash;
            forwarding_header.transaction_id = trans_id;

            reload_message_body = reload_content;

            forwarding_header.via_list = new List<Destination>();
            forwarding_header.via_list.Add(new Destination(OriginatorNodeID));

            forwarding_header.destination_list = new List<Destination>();
            forwarding_header.destination_list.Add(destination);
            SignerIdentity myId = m_ReloadConfig.AccessController.MyIdentity;
            security_block = new SecurityBlock(rc, myId);
            /* Sign the message, create stream of body */

            security_block.SignMessage(m_ReloadConfig.OverlayHash,
              trans_id.ToString(), reload_message_body);
        }
Esempio n. 22
0
 /// <summary>
 /// Use this contructor to obtain signature from bytes.
 /// </summary>
 /// <param name="config">The stack configuration</param>
 public Signature(ReloadConfig config) {
   m_ReloadConfig = config;
 }
Esempio n. 23
0
 public ReloadMessage(ReloadConfig rc, NodeId LastHopNodeId)
 {
     m_LastHopNodeId = LastHopNodeId;
     m_ReloadConfig = rc;
 }
Esempio n. 24
0
    public Signature(UInt32 overlay, string transactionId, byte[] messageContents, SignerIdentity signerIdentity, ReloadConfig config)
    {
        m_ReloadConfig = config;

        algorithm = new SignatureAndHashAlgorithm(HashAlgorithm.sha256,
          ReloadGlobals.SignatureAlg);
        identity = signerIdentity;
        /* Compute signature */

        byte[] bOverlay = BitConverter.GetBytes(overlay);
        byte[] bTransId = Encoding.Unicode.GetBytes(transactionId);
        byte[] bId = Encoding.Unicode.GetBytes(identity.ToString());

        byte[] sig = new byte[bOverlay.Length + bTransId.Length + messageContents.Length + bId.Length];
        System.Buffer.BlockCopy(bOverlay, 0, sig, 0, bOverlay.Length);
        System.Buffer.BlockCopy(bTransId, 0, sig, bOverlay.Length, bTransId.Length);
        System.Buffer.BlockCopy(messageContents, 0, sig, bOverlay.Length + bTransId.Length, messageContents.Length);
        System.Buffer.BlockCopy(bId, 0, sig, bOverlay.Length + bTransId.Length + messageContents.Length, bId.Length);

        signatureValue = Sign(sig);
    }
Esempio n. 25
0
 public ReloadMessage(ReloadConfig rc)
 {
     m_ReloadConfig = rc;
 }
Esempio n. 26
0
 public ForwardingLayer(Machine machine) {
   m_transport = machine.Transport;
   m_topology = machine.Topology;
   m_flm = machine.Interface_flm;
   m_ReloadConfig = machine.ReloadConfig;
 }
Esempio n. 27
0
        public static void ScheduleChecks(CheckList checkList, ReloadConfig.LogHandler logger)
        {
            // RFC 5245, ICE, Section 16.2:
            const int TA = 500;

            // Check Thread references
            List<Thread> checkThreads = new List<Thread>();

            // FIFO Queue for triggered checks
            List<CandidatePair> triggeredCheckQueue = new List<CandidatePair>();

            // order check list by pair-priority
            checkList.candidatePairs = checkList.candidatePairs.OrderBy(item => item.pairPriority).Reverse().ToList();

            while (true)
            {

                /* RFC 5245, ICE, Section 5.8:
                When the timer fires, the agent removes the top pair
                from the triggered check queue, performs a connectivity check on that
                pair, and sets the state of the candidate pair to In-Progress.  If
                there are no pairs in the triggered check queue, an ordinary check is
                sent.
                */

                // triggered check
                if (triggeredCheckQueue.Count > 0)
                {
                    // TODO !!!
                }

                // ordinary check
                // When the timer fires and there is no triggered check to be sent, the
                // agent MUST choose an ordinary check
                else
                {
                    // Find the highest-priority pair in that check list that is in the Waiting state, if there is one
                    CandidatePair waitingCandPair = null;
                    if (checkList.candidatePairs.Any(item => item.state == CandidatePairState.Waiting))
                    {
                        waitingCandPair = checkList.candidatePairs.First(item => item.state == CandidatePairState.Waiting);
                    }

                    // If there is such a pair
                    if (waitingCandPair != null)
                    {
                        // Send a STUN check from the local candidate of that pair to the
                        // remote candidate of that pair.  The procedures for forming the
                        // STUN request for this purpose are described in Section 7.1.2.

                        // Set the state of the candidate pair to In-Progress
                        waitingCandPair.state = CandidatePairState.InProgress;

                        Thread check = new Thread(() => PeformCheck(waitingCandPair, logger));
                        check.Start();
                        checkThreads.Add(check);

                        //// Set the state of the candidate pair to In-Progress
                        //waitingCandPair.state = CandidatePairState.InProgress;
                    }

                    // If there is no such pair
                    else
                    {
                        // Find the highest-priority pair in that check list that is in the Frozen state, if there is one
                        CandidatePair frozenCandPair = null;
                        if (checkList.candidatePairs.Any(item => item.state == CandidatePairState.Frozen))
                        {
                            frozenCandPair = checkList.candidatePairs.First(item => item.state == CandidatePairState.Frozen);
                        }

                        // If there is such a pair
                        if (frozenCandPair != null)
                        {
                            // Unfreeze the pair
                            frozenCandPair.state = CandidatePairState.Waiting;

                            // Set the state of the candidate pair to In-Progress
                            frozenCandPair.state = CandidatePairState.InProgress;

                            // Perform a check for that pair, causing its state to transition to In-Progress
                            Thread check = new Thread(() => PeformCheck(frozenCandPair, logger));
                            check.Start();
                            checkThreads.Add(check);

                            //// Set the state of the candidate pair to In-Progress
                            //frozenCandPair.state = CandidatePairState.InProgress;
                        }

                        // If there is no such pair
                        else
                        {
                            // Terminate the timer for that check list
                            break;
                        }
                    }

                }


                // wait N*TA (N = 1, just one media stream in RELOAD)
                Thread.Sleep(TA);
            }

            // wait for all threads
            foreach (Thread checkThread in checkThreads)
            {
                checkThread.Join();
            }
        }
Esempio n. 28
0
        // markus end


        public ReloadFLM(ReloadConfig reloadConfig)
        {
            m_ReloadConfig = reloadConfig;
            m_DispatcherQueue = m_ReloadConfig.DispatcherQueue;
            link.ReloadFLMEventHandler += new ReloadFLMEvent(link_ReloadFLMEventHandler);
        }
Esempio n. 29
0
 public Statistics(ReloadConfig reloadConfig) {
   m_ReloadConfig = reloadConfig;
   Reset();
 }