示例#1
0
        /// <summary>
        /// resuelve un nombre, se le pasa un objeto NodeBind sin direccion
        /// física y devuelve la dirección física correspondiente con el nodeId
        /// del objeto NodeBind pasado
        /// </summary>
        /// <param name="nodeId"></param>
        /// <returns></returns>
        public NodeBind Resolve(NodeId nodeId)
        {
            NodeBind ret = null;

            try
            {
                if (tableInner.ContainsKey(nodeId))
                {
                    DirectoryEntry entry = new DirectoryEntry();
                    if (tableInner.TryGetValue(nodeId, out entry))
                    {
                        if (entry.RoutedBySeed)
                        {
                            ret = entry.SeedBind;
                        }
                        else
                        {
                            ret = entry.NodeBind;
                        }
                    }
                }
                else if (localNode.Sessions.ExistsByNodeId(nodeId))
                {
                    // buscamos en las sesiones propias y sino en las resoluciones propias
                    ISessionRequest session = localNode.Sessions.GetSession(nodeId);
                    ret = session.NodeBindApplicant;
                }
                else
                {
                    // ISessionRequest[] seeds = localNode.Seeds.CloneArray();
                    // foreach (ISessionRequest seed in seeds)
                    // IEnumerator<KeyValuePair<string, ISessionRequest>> seed = localNode.Seeds.GetArray();
                    foreach (ISessionRequest seed in localNode.Seeds.GetArray())
                    {
                        ResolveRequest rreq  = new ResolveRequest(nodeId, localNode);
                        ResolveReply   reply = (ResolveReply)localNode.SendRequest(rreq, seed.NodeBindRemote);
                        if (reply != null)
                        {
                            if (reply.resolvedOk)
                            {
                                DirectoryEntry entry = new DirectoryEntry(seed.NodeBindRemote, reply.resolvedNodeBind);
                                localNode.Directory.AddEntryInner(entry);
                                ret = reply.resolvedNodeBind;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Node.LogAppendLine(e);
            }
            return(ret);
        }
示例#2
0
        public override void ArrivedAtDestination(Node overlayNode, Message msg)
        {
            ResolveReply reply = new ResolveReply(this);

            NodeBind nodeBind = overlayNode.Directory.ResolveOuter(requestNodeId);

            if (nodeBind != null)
            {
                reply.resolvedNodeBind = nodeBind;
                reply.resolvedOk       = true;
            }
            else
            {
                reply.resolvedOk = false;
            }

            overlayNode.SendReply(reply, msg.Source);
        }