Пример #1
0
        /// <summary>
        ///   this node joins to the network, process:
        ///   1. add know nodes to this nodes k-bucket
        ///   2. perform a NodeLookUp
        /// </summary>
        /// <remarks>
        ///   After FindNode is called the <paramref name = "knownNodesIdentifiers" /> knows about
        ///   the existence of this node...
        /// </remarks>
        /// <param name = "knownNodesIdentifiers"></param>
        public void JoinToNetwork(IEnumerable <NodeIdentifier <TKey> > knownNodesIdentifiers)
        {
            // 1. add known items to the routing table
            foreach (var nodeIdentifier in knownNodesIdentifiers)
            {
                RoutingTable.Add(nodeIdentifier);
            }

            // 2. Perform a Node Look up on the own node id
            JoinToNetwork();
        }
Пример #2
0
        public KademeliaSetHandler(RoutingTable <TKey> routingTable)
        {
            RoutingTable = routingTable;
//            KadCore = new SetKadCore<TKey, TValue>(routingTable, CreateClientFromNodeId);
        }
Пример #3
0
 /// <summary>
 ///   Initializes a new instance of <see cref = "kadCore{TKey,TValue}" /> with the
 ///   default settings.
 /// </summary>
 /// <param name = "routingTable">routing table with the known node addresses</param>
 public KadCore(RoutingTable <TKey> routingTable,
                Func <NodeIdentifier <TKey>, IKadNode <TKey, TValue> > createClientFromNodeIdDelegate)
     : this(routingTable, KademeliaSettings.Default, createClientFromNodeIdDelegate)
 {
 }
Пример #4
0
        private IEnumerable <NodeIdentifier <TKey> > NodeLookUp(TKey key,
                                                                IEnumerable <NodeIdentifier <TKey> > knownClosestNodes)
        {
            // convert the closest nodes to a list to prevent multiple enumerations
            List <NodeIdentifier <TKey> > closestNodes = knownClosestNodes.ToList();

            List <NodeIdentifier <TKey> > orderedNodes = closestNodes.ToObservable()
                                                         .CachedSelectMany(nodeId =>
            {
                IKadNode <TKey, TValue> client = CreateClientFromNodeId(nodeId);
                FindNodeResult <TKey> nodes    = client.FindNode(key, NodeIdentifier);
                return(Observable.Return(nodes));
            }, maxConcurrent: Settings.Cita)
                                                         .SelectMany(findNodeResult => findNodeResult.Nodes)
                                                         .Merge(closestNodes.ToObservable())
                                                         .Distinct()
                                                         .Do(RegisterNewNode)
                                                         .Timeout(Settings.ClientTimeOut)
                                                         .OnErrorResumeNext(Observable.Empty <NodeIdentifier <TKey> >())
                                                         .ToEnumerable()
                                                         .OrderBy(nodeId => nodeId.NodeId,
                                                                  new LamdaComparer <TKey>((n1, n2) => RoutingTable.DistanceComparer(n1, n2, key)))
                                                         .Take(Settings.K)
                                                         .ToList();

            return(orderedNodes.SequenceEqual(closestNodes)
                       ? orderedNodes
                       : NodeLookUp(key, orderedNodes));
        }
Пример #5
0
 /// <summary>
 ///   returns the k closest contacts to the given key
 /// </summary>
 /// <param name = "key"></param>
 /// <returns></returns>
 protected IEnumerable <NodeIdentifier <TKey> > GetKClosestContacts(TKey key)
 {
     return(RoutingTable.NearTo(key).Where(IsOnline).Take(Settings.K));
 }
Пример #6
0
 public SetKadCore(RoutingTable <TKey> routingTable, KademeliaSettings settings,
                   Func <NodeIdentifier <TKey>, ISetKadNode <TKey, TValue> > createClientFromNodeIdDelegate,
                   NodeIdentifier <TKey> nodeIdentifier)
     : base(routingTable, settings, createClientFromNodeIdDelegate, nodeIdentifier)
 {
 }
Пример #7
0
 public SetKadCore(RoutingTable <TKey> routingTable,
                   Func <NodeIdentifier <TKey>, ISetKadNode <TKey, TValue> > createClientFromNodeIdDelegate)
     : base(routingTable, createClientFromNodeIdDelegate)
 {
 }