/// <summary> /// Store the pair (key, value) /// </summary> /// <param name = "key"></param> /// <param name = "value"></param> /// <param name = "callerIdentifier"></param> public virtual void Store(TKey key, TValue value, NodeIdentifier <TKey> callerIdentifier = null) { Debug.Assert(KadCore.NodeIdentifier != null, "kadCore.NodeIdentifier != null"); // notify about the existence of the caller node if (callerIdentifier != null) { OnNewNodeNotice(callerIdentifier); } if (DataStore.Contains(key)) { DataStore[key] = value; } else { DataStore.Add(key, value); } KadLogger.Info(string.Format("Store method called with params ({0},{1}) from {2} ", key, value, callerIdentifier)); if (callerIdentifier == null) { KadLogger.Warn("Caller identifier is null."); } }
public virtual bool Remove(TKey key, NodeIdentifier <TKey> callerIdentifier = null) { Debug.Assert(KadCore.NodeIdentifier != null, "kadCore.NodeIdentifier != null"); // notify about the existence of the caller node if (callerIdentifier != null) { OnNewNodeNotice(callerIdentifier); } KadLogger.Info(string.Format("Remove method called with key {0} from {1} ", key, callerIdentifier)); if (callerIdentifier == null) { KadLogger.Warn("Caller identifier is null."); } return(DataStore.Remove(key)); }
public void StoreIntoLookUp(TKey key, TValue value) { // 1. find the closest nodes to the given key IEnumerable <NodeIdentifier <TKey> > closestNodes = NodeLookUp(key); // 2. store the (key,value) pair in those nodes foreach (var node in closestNodes) { try { ISetKadNode <TKey, TValue> client = CreateSetClientFromNodeId(node); client.StoreInto(key, value, NodeIdentifier); } catch (EndpointNotFoundException e) { KadLogger.Error("No endpoint found, probably because the node is offline.", e); } } }
/// <summary> /// return the K closest nodes to the key that this node knows about. /// </summary> /// <param name = "key"></param> /// <param name = "callerIdentifier"></param> /// <returns></returns> public virtual FindNodeResult <TKey> FindNode(TKey key, NodeIdentifier <TKey> callerIdentifier = null) { Debug.Assert(KadCore.NodeIdentifier != null, "kadCore.NodeIdentifier != null"); // notify about the existence of the caller node if (callerIdentifier != null) { OnNewNodeNotice(callerIdentifier); } KadLogger.Info(string.Format("FindNode method called with key {0} from {1} ", key, callerIdentifier)); if (callerIdentifier == null) { KadLogger.Warn("Caller identifier is null."); } // returns the K nearest elements that this node knows about around the key); return(new FindNodeResult <TKey>(GetKClosestContacts(key))); }
/// <summary> /// If the node has received a Store with that key, then return the value, /// if not, return the K closest nodes to the key that this node knows about. /// </summary> /// <param name = "key"></param> /// <param name = "callerIdentifier"></param> /// <returns></returns> public virtual FindValueResult <TKey, TValue> FindValue(TKey key, NodeIdentifier <TKey> callerIdentifier = null) { Debug.Assert(KadCore.NodeIdentifier != null, "kadCore.NodeIdentifier != null"); // notify about the existence of the caller node if (callerIdentifier != null) { OnNewNodeNotice(callerIdentifier); } KadLogger.Info(string.Format("FindValue method called with key {0} from {1} ", key, callerIdentifier)); if (callerIdentifier == null) { KadLogger.Warn("Caller identifier is null."); } return(DataStore.Contains(key) ? new FindValueResult <TKey, TValue>(DataStore[key]) : new FindValueResult <TKey, TValue>(GetKClosestContacts(key))); }
public virtual HeartBeat <TKey> Ping(NodeIdentifier <TKey> callerIdentifier = null) { Debug.Assert(KadCore.NodeIdentifier != null, "kadCore.NodeIdentifier != null"); // notify about the existence of the caller node if (callerIdentifier != null) { OnNewNodeNotice(callerIdentifier); } KadLogger.Info("Ping method called from " + callerIdentifier); if (callerIdentifier == null) { KadLogger.Warn("Caller identifier is null."); } KadLogger.Info("Returning NodeIdentifier: " + KadCore.NodeIdentifier); // This method could return valuable information about current/max performance, payload, etc. // also some data about the host: machine name, user, total files shared, etc. return(new HeartBeat <TKey>(KadCore.NodeIdentifier)); }
/// <summary> /// Called every time that the Kademlia node notice a new node in the network. Can be /// either because the new node make a RPC request or was found in a node lookUp procedure. /// </summary> /// <param name = "nodeIdentifier">New node identifier.</param> protected virtual void OnNewNodeNotice(NodeIdentifier <TKey> nodeIdentifier) { KadCore.RegisterNewNode(nodeIdentifier); KadLogger.Info("New node noticed, adding it to the routing table. Node: " + nodeIdentifier); }