Inheritance: EdgeListener
Exemplo n.º 1
0
 public void HandleRpc(ISender caller, string meth, IList args, object state)
 {
     if (meth == "create")
     {
         Edge             calling_edge = (Edge)((ReqrepManager.ReplyState)caller).ReturnPath;
         string           remote_path  = (string)args[0];
         string           local_path   = (string)args[1];
         PathEdgeListener el           = _pel_map[local_path];
         if (el.IsStarted)
         {
             PathEdge npe = new PathEdge(this, calling_edge, local_path, remote_path);
             lock ( _sync ) {
                 //We don't announce yet, wait till we get some data, which
                 //verifies that the other side has seen it.
                 _unannounced[calling_edge] = npe;
             }
             //So the new Edge has been announced.
             Rpc.SendResult(state, true);
         }
         else
         {
             throw new Exception(
                       String.Format("PathEdgeListener({0}) not started", local_path));
         }
     }
     else
     {
         throw new AdrException(-32601, "No Handler for method: " + meth);
     }
 }
Exemplo n.º 2
0
 public CreateState(PathEdgeListener pel, string rem, string loc,
                    EdgeListener.EdgeCreationCallback ecb, bool root)
 {
     _pel       = pel;
     RemotePath = rem;
     LocalPath  = loc;
     ECB        = ecb;
     _root      = root;
 }
Exemplo n.º 3
0
        /** Removes a path from the PEM and Closes it if it is still operational.
         */
        public void RemovePath(string path)
        {
            PathEdgeListener pel = null;

            lock ( _sync ) {
                if (!_pel_map.TryGetValue(path, out pel))
                {
                    return;
                }
                _pel_map.Remove(path);
            }

            if (pel != null)
            {
                pel.Stop();
            }
        }
Exemplo n.º 4
0
        /**
         * Creates a new Path, the root one, if it doesn't exist, otherwise a
         * random path.
         */
        public PathEdgeListener CreatePath()
        {
            Random           rand = new Random();
            PathEdgeListener pel  = null;

            lock ( _sync ) {
                string path = Root;
                while (_pel_map.ContainsKey(path))
                {
                    path = String.Format("/{0}", rand.Next().ToString());
                }

                pel            = new PathEdgeListener(this, path, _el);
                _pel_map[path] = pel;
            }

            return(pel);
        }
Exemplo n.º 5
0
        /** create a new PathEdgeListener
         */
        public PathEdgeListener CreatePath(string path)
        {
            PathEdgeListener new_pel = null;

            if (!path[0].Equals('/'))
            {
                path = String.Format("/{0}", path);
            }
            lock ( _sync ) {
                //Make sure the path doesn't already exist,
                if (_pel_map.ContainsKey(path))
                {
                    throw new Exception("Path already exists");
                }
                else
                {
                    new_pel        = new PathEdgeListener(this, path, _el);
                    _pel_map[path] = new_pel;
                }
            }
            return(new_pel);
        }
Exemplo n.º 6
0
        /**
         * Creates a new Path, the root one, if it doesn't exist, otherwise a
         * random path.
         */
        public PathEdgeListener CreatePath()
        {
#if BRUNET_SIMULATOR
            Random rand = Node.SimulatorRandom;
#else
            Random rand = new Random();
#endif
            PathEdgeListener pel = null;

            lock ( _sync ) {
                string path = Root;
                while (_pel_map.ContainsKey(path))
                {
                    path = String.Format("/{0}", rand.Next().ToString());
                }

                pel            = new PathEdgeListener(this, path, _el);
                _pel_map[path] = pel;
            }

            return(pel);
        }
Exemplo n.º 7
0
 public CreateState(PathEdgeListener pel, string rem, string loc,
                    EdgeListener.EdgeCreationCallback ecb, bool root) {
   _pel = pel;
   RemotePath = rem;
   LocalPath = loc;
   ECB = ecb;
   _root = root;
 }
Exemplo n.º 8
0
    /**
     * Creates a new Path, the root one, if it doesn't exist, otherwise a
     * random path.
     */
    public PathEdgeListener CreatePath()
    {
      Random rand = new Random();
      PathEdgeListener pel = null;

      lock( _sync ) {
        string path = Root;
        while( _pel_map.ContainsKey(path) ) {
          path = String.Format("/{0}", rand.Next().ToString());
        }

        pel = new PathEdgeListener(this, path, _el);
        _pel_map[path] = pel;
      }

      return pel;
    }
Exemplo n.º 9
0
 /** create a new PathEdgeListener
  */
 public PathEdgeListener CreatePath(string path) {
   PathEdgeListener new_pel = null;
   if(!path[0].Equals('/')) {
     path = String.Format("/{0}", path);
   }
   lock( _sync ) {
     //Make sure the path doesn't already exist,
     if( _pel_map.ContainsKey(path) ) {
       throw new Exception("Path already exists");
     }
     else {
       new_pel = new PathEdgeListener(this, path, _el);
       _pel_map[path] = new_pel;
     }
   }
   return new_pel;
 }
Exemplo n.º 10
0
    /**
     * Creates a new Path, the root one, if it doesn't exist, otherwise a
     * random path.
     */
    public PathEdgeListener CreatePath()
    {
#if BRUNET_SIMULATOR
      Random rand = Node.SimulatorRandom;
#else
      Random rand = new Random();
#endif
      PathEdgeListener pel = null;

      lock( _sync ) {
        string path = Root;
        while( _pel_map.ContainsKey(path) ) {
          path = String.Format("/{0}", rand.Next().ToString());
        }

        pel = new PathEdgeListener(this, path, _el);
        _pel_map[path] = pel;
      }

      return pel;
    }
Exemplo n.º 11
0
        /** Handle incoming data on an Edge
         */
        public void HandleData(MemBlock data, ISender retpath, object state)
        {
            MemBlock rest_of_data;
            PType    p;

            if (state == null)
            {
                try {
                    p = PType.Parse(data, out rest_of_data);
                } catch (ParseException) {
                    ProtocolLog.WriteIf(ProtocolLog.Pathing, "Invalid PType from: " + data);
                    return;
                }
                p = PType.Parse(data, out rest_of_data);
            }
            else
            {
                //a demux has already happened:
                p            = (PType)state;
                rest_of_data = data;
            }

            if (PType.Protocol.Pathing.Equals(p))
            {
                /*
                 * We use a special PType to denote this transaction so
                 * we don't confuse it with other RepRep communication
                 */
                _rrm.HandleData(rest_of_data, retpath, null);
            }
            else if (PType.Protocol.Rpc.Equals(p))
            {
                /*
                 * Send this to the RpcHandler
                 */
                Rpc.HandleData(rest_of_data, retpath, null);
            }
            else
            {
                /*
                 * This is some other data
                 * It is either:
                 * 1) Time to announce an already created edge.
                 * 2) Assume this is a "default path" edge creation, to be backwards
                 * compatible
                 */
                Edge     e  = null;
                PathEdge pe = null;
                try {
                    e = (Edge)retpath;
                    PathEdgeListener pel = null;
                    lock ( _sync ) {
                        if (_unannounced.TryGetValue(e, out pe))
                        {
                            //
                            _unannounced.Remove(e);
                            pel = _pel_map[pe.LocalPath];
                        }
                    }
                    if (pe == null)
                    {
                        if (!_pel_map.ContainsKey(Root))
                        {
                            ProtocolLog.WriteIf(ProtocolLog.Pathing, "No root, can't create edge");
                            if (e != null)
                            {
                                e.Close();
                            }
                            return;
                        }

                        /*
                         * This must be a "default path" incoming connection
                         */
                        pel = _pel_map[Root];
                        pe  = new PathEdge(this, e, Root, Root);
                    }
                    pel.SendPathEdgeEvent(pe);
                    pe.Subscribe();
                    pe.ReceivedPacketEvent(data);
                }
                catch (Exception x) {
                    if (pe != null)
                    {
                        //This closes both edges:
                        pe.Close();
                    }
                    else if (e != null)
                    {
                        ProtocolLog.WriteIf(ProtocolLog.Pathing,
                                            String.Format("Closing ({0}) due to: {1}", e, x));
                        e.Close();
                    }
                }
            }
        }