Пример #1
0
        /// <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.");
            }
        }
Пример #2
0
        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));
        }
Пример #3
0
        /// <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)));
        }
Пример #4
0
        /// <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)));
        }
Пример #5
0
        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));
        }