Наследование: IDataHandler, ISender, IActionQueue, ITAHandler
 public ManagedConnectionOverlord(Node node) {
   _sync = new Object();
   _active = false;
   _node = node;
   _connection_state = new Dictionary<Address, MCState>();
   _last_call = DateTime.MinValue;
 }
Пример #2
0
 public RpcDht(IDht dht, Node node) {
   LocalUseOnly = true;
   _channels = new Brunet.Collections.Cache(100);
   _node = node;
   _dht = dht;
   _node.Rpc.AddHandler("DhtClient", this);
 }
Пример #3
0
 public RpcDht(IDht dht, Node node) {
   LocalUseOnly = true;
   _bqs = new Cache(100);
   _node = node;
   _dht = dht;
   _node.Rpc.AddHandler("DhtClient", this);
 }
Пример #4
0
		//protected object _sync;

		public DeetooCluster(Node cnode, Node qnode, double x, double y) {
			//_sync = new object();
			_cnode = cnode;
			_qnode = qnode;
			_coor_x = x;
			_coor_y = y;
		}
Пример #5
0
    /// <summary> Occassionally nodes will get a true return from a allocation
    /// attempt, in order to prevent this, we reissue all dhcp requests after
    /// getting "connected" to the overlay.</summary>
    protected void StateChangeHandler(Node n, Node.ConnectionState state) {
      List<MemBlock> ips = null;

      lock(_sync) {
        if(state == Node.ConnectionState.Connected) {
          if(_connected) {
            return;
          }
          AppNode.Node.StateChangeEvent -= StateChangeHandler;
          _connected = true;
        } else {
          return;
        }

        ips = new List<MemBlock>(_ip_to_ether.Keys.Count);
        foreach(MemBlock ip in _ip_to_ether.Keys) {
          ips.Add(ip);
        }
      }

      WaitCallback callback = delegate(object o) {
        // Get a new Dhcp server so we get new state!
        DhcpServer dhcp_server = GetDhcpServer();
        foreach(MemBlock ip in ips) {
          try {
            dhcp_server.RequestLease(ip, true, AppNode.Node.Address.ToString(),
                _ipop_config.AddressData.Hostname);
          } catch(Exception e) {
            ProtocolLog.WriteIf(IpopLog.DhcpLog, e.Message);
          }
        }
      };

      ThreadPool.QueueUserWorkItem(callback, null);
    }
    public StructuredNearConnectionOverlord(Node n)
    {
      _sync = new Object();
      lock( _sync ) {
        _node = n;
        _rand = new Random();
        _connectors = new Hashtable();
        _last_connection_time = DateTime.UtcNow;
      /**
       * Every heartbeat we assess the trimming situation.
       * If we have excess edges and it has been more than
       * _trim_wait_time heartbeats then we trim.
       */
        _last_retry_time = DateTime.UtcNow;
        _current_retry_interval = _DEFAULT_RETRY_INTERVAL;

        /**
         * Information related to the target selector feature.
         * Includes statistics such as trim rate and connection lifetimes.
         */
        
        _start_time = DateTime.UtcNow;
        
        /*
         * Register event handlers after everything else is set
         */
        //Listen for connection events:
        _node.ConnectionTable.DisconnectionEvent += DisconnectHandler;
        _node.ConnectionTable.ConnectionEvent += ConnectHandler;
        _node.ConnectionTable.StatusChangedEvent += StatusChangedHandler;
        
        _node.HeartBeatEvent += CheckState;
      }
    }
    public TunnelEdgeListener(Node node, ITunnelOverlap ito, IForwarderSelectorFactory iasf)
    {
      _ito = ito;
      _iasf = iasf;
      _oco = new OverlapConnectionOverlord(node);
      _node = node;
      _running = 0;
      _started = 0;
      _id_to_tunnel = new Dictionary<int, TunnelEdge>();
      _sync = new object();

      TransportAddress ta = new TunnelTransportAddress(node.Address, new List<Address>());
      ArrayList local_tas = new ArrayList(1);
      local_tas.Add(ta);
      _local_tas = local_tas;

      _node.DemuxHandler.GetTypeSource(PType.Protocol.Tunneling).Subscribe(this, null);
      _node.ConnectionTable.ConnectionEvent += ConnectionHandler;
      _node.ConnectionTable.DisconnectionEvent += DisconnectionHandler;

      ConnectionList cons = _node.ConnectionTable.GetConnections(ConnectionType.Structured);
      Interlocked.Exchange(ref _connections, cons);
      _node.Rpc.AddHandler("tunnel", this);
      _oco_trim_timer = Brunet.Util.FuzzyTimer.Instance.DoEvery(OcoTrim, _oco_trim_timeout, 0);
    }
Пример #8
0
 public Agent(Node n, IAcceptor read_acceptor, IAcceptor write_acceptor) {
   _rand = new Random();
   /**
    * @todo Make a heartbeat handler which will use the Node HeartbeatEvent
    * to resend packets after the timeout
    */
 }
    ///<summary>Verify the edge by comparing the address in the certificate to
    ///the one provided in the overlay.</summary>
    public static bool AddressInSubjectAltName(Node node, Edge e, Address addr) {
      SecureEdge se = e as SecureEdge;
      if(se == null) {
        throw new Exception("Invalid edge type!");
      }

      return se.SA.VerifyCertificateBySubjectAltName(addr.ToString());
    }
Пример #10
0
 /**
 <summary>A default Dht client provides a DEGREE of 1 and a sychronous wait
 time of up to 60 seconds.</summary>
 <param name ="node">The node to provide service for.</param>
 */
 public Dht(Node node) {
   this.node = node;
   _rpc = RpcManager.GetInstance(node);
   _table = new TableServer(node);
   DEGREE = 1;
   MAJORITY = 1;
   DELAY = 60000;
 }
Пример #11
0
 /// <summary>Initiates a RpcProxyHandler instance. It uses reflection for rpc call.
 /// Thus, it does not have to inherit IRpcHanler.This instance keeps Entry
 /// to keep track of key, value, and ttl</summary>
 /// <param name="node">node which is currently connected.</param>
 /// <param name="dht">IDht instance</param>
 public RpcDhtProxy(IDht dht, Node node)
 {
   _entries = new Dictionary<MemBlock, Dictionary<MemBlock, Entry>>();
   _rpc = node.Rpc;
   _dht = dht;
   _sync = new Object();
   _rpc.AddHandler("RpcDhtProxy", this);
 }
Пример #12
0
 /**
  * Returns an instance of an ISender, given its URI representation.
  * @param n node on which the sender is attached. 
  * @param uri URI representation of the sender.
  * @returns an ISender object.
  * @throws SenderFactoryException when URI is invalid or unsupported. 
  */
 public static ISender CreateInstance(Node n, string uri) {
   int varidx;
   try {
     string type = GetScheme(uri, out varidx);
     return _handlers[type](n, uri);
   } catch {
     throw new SenderFactoryException("Cannot parse URI: " + uri);         
   }
 }
Пример #13
0
 protected static AHSender CreateInstance(Node n, string uri) {
   string s = uri.Substring(7);
   string []ss = s.Split(SenderFactory.SplitChars);
   string []dest = ss[1].Split(SenderFactory.Delims);
   Address target = AddressParser.Parse(dest[1]);
   string mode = (ss[2].Split(SenderFactory.Delims))[1];
   ushort option = SenderFactory.StringToUShort(mode);
   return new AHSender(n, target, option);
 }
Пример #14
0
    protected void ConnectionHandlerTest(Node node0, Node node1,
        ConnectionHandler ch0, ConnectionHandler ch1)
    {
      Console.WriteLine(node0.Address + " " + node1.Address);
      var mdh0 = new MockDataHandler();
      var mdh1 = new MockDataHandler();
      MemBlock zero = MemBlock.Reference(new byte[] {0});
      EventHandler cb = delegate(object o, EventArgs ea) {
        Assert.AreEqual(o, zero, "Zero");
      };

      mdh0.HandleDataCallback += cb;
      mdh1.HandleDataCallback += cb;
      ch0.Subscribe(mdh0, null);
      ch1.Subscribe(mdh1, null);

      Assert.AreEqual(mdh0.Count, 0, "MDH0 0");
      Assert.AreEqual(mdh1.Count, 0, "MDH1 0");
      ch0.ConnectTo(node1.Address);
      Assert.IsTrue(AreConnected(node0, node1), "ConnectionHandler ConnectTo");
      SimpleTimer.RunSteps(fifteen_mins * 2);
      Assert.IsFalse(Simulator.AreConnected(node0, node1));
      ch0.Send(node1.Address, zero);
      SimpleTimer.RunSteps(fifteen_mins / 60);
      Assert.AreEqual(mdh0.Count, 0, "MDH0 1");
      Assert.AreEqual(mdh1.Count, 0, "MDH1 1");
      Assert.IsTrue(AreConnected(node0, node1), "ConnectionHandler ConnectTo");
      SimpleTimer.RunSteps(fifteen_mins / 3);
      ch0.Send(node1.Address, zero);
      SimpleTimer.RunSteps(fifteen_mins / 60);
      Assert.AreEqual(mdh0.Count, 0, "MDH0 2");
      Assert.AreEqual(mdh1.Count, 1, "MDH1 2");
      Assert.IsTrue(Simulator.AreConnected(node0, node1), "Continuous 0");
      SimpleTimer.RunSteps(fifteen_mins / 3);
      ch0.Send(node1.Address, zero);
      SimpleTimer.RunSteps(fifteen_mins / 60);
      Assert.AreEqual(mdh0.Count, 0, "MDH0 3");
      Assert.AreEqual(mdh1.Count, 2, "MDH1 3");
      Assert.IsTrue(Simulator.AreConnected(node0, node1), "Continuous 1");
      SimpleTimer.RunSteps(fifteen_mins / 3);
      ch0.Send(node1.Address, zero);
      SimpleTimer.RunSteps(fifteen_mins / 60);
      Assert.AreEqual(mdh0.Count, 0, "MDH0 4");
      Assert.AreEqual(mdh1.Count, 3, "MDH1 4");
      Assert.IsTrue(Simulator.AreConnected(node0, node1), "Continuous 2");
      SimpleTimer.RunSteps(fifteen_mins / 3);
      ch1.Send(node0.Address, zero);
      SimpleTimer.RunSteps(fifteen_mins / 60);
      Assert.AreEqual(mdh0.Count, 1, "MDH0 5");
      Assert.AreEqual(mdh1.Count, 3, "MDH1 5");
      Assert.IsTrue(Simulator.AreConnected(node0, node1), "Continuous 3");
      SimpleTimer.RunSteps(fifteen_mins * 2);
      Assert.IsFalse(Simulator.AreConnected(node0, node1), "Dead");
      Assert.AreEqual(mdh0.Count, 1, "MDH0 6");
      Assert.AreEqual(mdh1.Count, 3, "MDH1 6");
    }
Пример #15
0
 public void Add(Node n) {
   lock( _sync ) {
     _node_list.Add(n);  
     _sorted_adds.Add(n.Address);
     _sorted_adds.Sort(new AHAddressComparer());
     //monitor the connection table:
     ConnectionTable ct = n.ConnectionTable;
     _ctable_to_node[ ct ] = n; 
     ct.ConnectionEvent += new EventHandler(this.ConnectionTableChangeHandler);
     ct.DisconnectionEvent += new EventHandler(this.ConnectionTableChangeHandler);
   }
 }
 /**
  * You should subscribe this to a Node, with the state being the node
  * it is subscribed to.  It can work for more than one node
  * simultaneously.
  */
 public ConnectionPacketHandler(Node n)
 {
   _sync = new object();
   _edge_to_cphstate = new Hashtable();
   _node = n;
   _disconnecting = 0;
   //When Disconnect is called, set disconnecting to true, disallowing new
   //connections.
   _node.DepartureEvent += delegate(object o, EventArgs a) {
     Interlocked.Exchange(ref _disconnecting, 1);
   };
 }
Пример #17
0
        public LocalHT()
        {
            AHAddress addr = new AHAddress(new RNGCryptoServiceProvider());
              Node brunetNode = new StructuredNode(addr);
              RpcManager rpc = RpcManager.GetInstance(brunetNode);
              this._ts = new TableServer(brunetNode);
              this._node = brunetNode;

            #if FUSE_DEBUG
              //Having some init data isn't bad
              string key = FuseDhtUtil.GenDhtKey("testbasedir", "testkey1", "ipop_ns");
              this.Put(key, "testvalue1", 5000);
              this.Put(key, "testvalue2", 3000);
            #endif
        }
Пример #18
0
    /**
    <summary>Creates a new TableServer object and registers it to the "dht"
    handler in the node's RpcManager.</summary>
    <param name="node">The node the dht is to serve from.</param>
    */
    public TableServer(Node node) {
      _sync = new Object();
      _transfer_sync = new Object();

      _node = node;
      _rpc = node.Rpc;

      _data = new TableServerData(_node);
      lock(_transfer_sync) {
        node.ConnectionTable.ConnectionEvent += this.ConnectionHandler;
        node.ConnectionTable.DisconnectionEvent += this.ConnectionHandler;
        _node.StateChangeEvent += StateChangeHandler;
      }

      _rpc.AddHandler("dht", this);
    }
Пример #19
0
    public LocalConnectionOverlord(Node node) {
      _sync = new Object();
      _allow_localcons = false;
      _active = false;
      _local_addresses = new List<AHAddress>();
      _node = node;

      lock(_sync) {
        _rpc = RpcManager.GetInstance(node);
        _rpc.AddHandler("LocalCO", this);

        _node.HeartBeatEvent += CheckConnection;
        _node.StateChangeEvent += StateChangeHandler;
        _node.ConnectionTable.ConnectionEvent += ConnectHandler;
        _node.ConnectionTable.DisconnectionEvent += DisconnectHandler;
        _last_announce_call = DateTime.MinValue;
        _last_activate_call = DateTime.MinValue;
      }
    }
    public StructuredShortcutConnectionOverlord(Node n)
    {
      _sync = new Object();
      lock( _sync ) {
        _node = n;
        _rand = new Random();
        _last_connection_time = DateTime.UtcNow;
      /**
       * Every heartbeat we assess the trimming situation.
       * If we have excess edges and it has been more than
       * _trim_wait_time heartbeats then we trim.
       */
        _last_retry_time = DateTime.UtcNow;
        _current_retry_interval = _DEFAULT_RETRY_INTERVAL;

        /**
         * Information related to the target selector feature.
         * Includes statistics such as trim rate and connection lifetimes.
         */
        
        _target_selector = new DefaultTargetSelector();
        _last_optimize_time = DateTime.UtcNow;
        _sum_con_lifetime = 0.0;
        _start_time = DateTime.UtcNow;
        _trim_count = 0;
        _shortcuts = 0;

        /*
         * Register event handlers after everything else is set
         */
        //Listen for connection events:
        _node.ConnectionTable.DisconnectionEvent += DisconnectHandler;
        _node.ConnectionTable.ConnectionEvent += ConnectHandler;
        
        _node.HeartBeatEvent += CheckState;
        _node.HeartBeatEvent += CheckConnectionOptimality;
      }
    }
Пример #21
0
 public MapReduceTrace(Node n):base(n) {}
Пример #22
0
 /**
  * Constructor.
  * @param n local node
  */
 protected MapReduceTask(Node n) {
   _node = n;
   _task_name = new WriteOnce<string>();
 }
Пример #23
0
 /**
  * Static method to create RpcManager objects
  * @param node The node we work for
  * @deprecated use node.Rpc
  */
 public static RpcManager GetInstance(Node node) {
   return node.Rpc;
 }
Пример #24
0
 public RpcRoutingTestHandler(Node n) {
   _node = n;
 }
Пример #25
0
 public TunnelEdgeListener(Node node, ITunnelOverlap ito) :
   this(node, ito, new SimpleForwarderSelectorFactory())
 {
 }
Пример #26
0
 public TunnelEdgeListener(Node node) :
   this(node, new SimpleTunnelOverlap(), new SimpleForwarderSelectorFactory())
 {
 }
Пример #27
0
    /** 
     * Constructor. 
     * @param n local node
     * @param service local network coordinate service
     */
    public VivaldiTargetSelector(Node n, NCService service) {
      _sync = new object();
      _channel_to_state = new Hashtable();
      _node = n;
      _nc_service = service;
      _num_requests = 0;
#if VTS_DEBUG
      lock(_sync) {
        _node.StateChangeEvent += delegate(Node node, Node.ConnectionState s) {
          if( s == Node.ConnectionState.Joining ) {
            lock(_class_lock) {
              _vts_nodes[node] = null;
              if (_vts_nodes.Keys.Count == 1) { //first node
                Console.Error.WriteLine("Starting the VTS checkpoint thread. ");
                _checkpoint_thread = new Thread(CheckpointThread);
                _checkpoint_thread_finished = 0;
                _checkpoint_thread.Start();
              }
            }
          }
        };
        _node.StateChangeEvent += delegate(Node node, Node.ConnectionState s) {
          if( s == Node.ConnectionState.Disconnected ) {
            lock(_class_lock) {
              _vts_nodes.Remove(node);
              if (_vts_nodes.Keys.Count == 0) { //last node to leave
                Console.Error.WriteLine("Interrupting the VTS checkpoint thread. ");
                Interlocked.Exchange(ref _checkpoint_thread_finished, 1);
                _checkpoint_thread.Interrupt();
                _checkpoint_thread.Join();
                Console.Error.WriteLine("Join with the VTS checkpoint thread (finished).");
              }
            }
          }
        };
      }
#endif
    }
Пример #28
0
 protected void StateChangeHandler(Node n, Node.ConnectionState state) {
   if(state == Node.ConnectionState.Connected) {
     lock(_sync) {
       _allow_localcons = true;
     }
   }
   else if(state == Node.ConnectionState.Leaving) {
     lock(_sync) {
       _active = false;
     }
   }
 }
Пример #29
0
 public LinkProtocolState(Linker l, TransportAddress ta, Edge e) {
   _linker = l;
   _node = l.LocalNode;
   _contype = l.ConType;
   _target_lock = null;
   _lm_reply = new WriteOnce<LinkMessage>();
   _x = new WriteOnce<Exception>();
   _con = new WriteOnce<Connection>();
   _ta = ta;
   _is_finished = 0;
   //Setup the edge:
   _e = e;
   _result = Result.None;
 }
Пример #30
0
 /// <summary>If we are or were connected in the right place, we accept DHT
 /// messages otherwise we ignore them.</summary>
 /// <param name="n">The node for this event.</param>
 /// <param name="state">The new state.</param>
 protected void StateChangeHandler(Node n, Node.ConnectionState state) {
   lock(_sync) {
     if(state == Node.ConnectionState.Leaving) {
       _online = false;
       DepartureHandler();
     } else if(state == Node.ConnectionState.Disconnected ||
         state == Node.ConnectionState.Offline) {
       _online = false;
     } else if(state == Node.ConnectionState.Connected) {
       _online = true;
     }
   }
 }