/**
 <summary>This handles only connection event for now.<\summary>
 <param name="node">The node the deetoo is to serve from.<\param>
 <param name="cl">The CacheList belongs to this node.<\param>
 */
 public DeetooHandler(Node node, CacheList cl) {
   _node = node;
   _rpc = RpcManager.GetInstance(node);
   _cl = cl;
   //NetworkSize = _node.NetworkSize;
   _local_network_size = _node.NetworkSize;
   _median_network_size = _node.NetworkSize;
   node.ConnectionTable.ConnectionEvent += this.GetEstimatedSize;
   node.ConnectionTable.DisconnectionEvent += this.GetEstimatedSize;
   node.ConnectionTable.ConnectionEvent += this.GetMedianEstimation;
   node.ConnectionTable.DisconnectionEvent += this.GetMedianEstimation;
   node.ConnectionTable.ConnectionEvent += this.ConnectionHandler;
   //_rpc.AddHandler("Deetoo", this);
 }
 public MapReduceQuery(Node n, CacheList cl): base(n) {
   _cl = cl;
 }
Example #3
0
    /**
    <summary>Creates a Brunet.Node, the resulting node will be available in
    the class as _node.</summary>
    <remarks>The steps to creating a node are first constructing it with a
    namespace, optionally adding local ip addresses to bind to, specifying
    local end points, specifying remote end points, and finally registering
    the dht.</remarks>
    */
    public virtual void CreateNode(string type) {
      NodeConfig node_config = null;
      StructuredNode current_node = null;
      AHAddress address = null;
      if (type == "cache") {
        node_config = _c_node_config;
        address = (AHAddress) AddressParser.Parse(node_config.NodeAddress);
        current_node = new StructuredNode(address, node_config.BrunetNamespace);
      }
      else if ( type == "query" ) {
        node_config = _q_node_config;
        address = (AHAddress) AddressParser.Parse(node_config.NodeAddress);
        current_node = new StructuredNode(address, node_config.BrunetNamespace);
      }
      else {
        throw new Exception("Unrecognized node type: " + type);
      }
      IEnumerable addresses = IPAddresses.GetIPAddresses(node_config.DevicesToBind);

      Brunet.EdgeListener el = null;
      foreach(NodeConfig.EdgeListener item in node_config.EdgeListeners) {
        int port = item.port;
        if (item.type =="tcp") {
          try {
            el = new TcpEdgeListener(port, addresses);
          }
          catch {
            el = new TcpEdgeListener(0, addresses);
          }
        }
        else if (item.type == "udp") {
          try {
            el = new UdpEdgeListener(port, addresses);
          }
          catch {
            el = new UdpEdgeListener(0, addresses);
          }
        }
        else {
          throw new Exception("Unrecognized transport: " + item.type);
        }
	current_node.AddEdgeListener(el);
      }
      el = new TunnelEdgeListener(current_node);
      current_node.AddEdgeListener(el);

      ArrayList RemoteTAs = null;
      if(node_config.RemoteTAs != null) {
        RemoteTAs = new ArrayList();
        foreach(String ta in node_config.RemoteTAs) {
          RemoteTAs.Add(TransportAddressFactory.CreateInstance(ta));
        }
	current_node.RemoteTAs = RemoteTAs;
      }

      try {
        if (node_config.NCService.Enabled) {
	  if (type == "cache") {
            _c_ncservice = new NCService(current_node, node_config.NCService.Checkpoint);
            if (node_config.NCService.OptimizeShortcuts) {
              current_node.Sco.TargetSelector = new VivaldiTargetSelector(current_node, _c_ncservice);
	    }
	  }
	  else {
            _q_ncservice = new NCService(current_node, node_config.NCService.Checkpoint);
            if (node_config.NCService.OptimizeShortcuts) {
              current_node.Sco.TargetSelector = new VivaldiTargetSelector(current_node, _q_ncservice);
	    }
	  }

        }
      } catch {}

      if (type == "cache") {
        _c_dht = new Dht(current_node, 3, 20);
        _cs = new CacheList(current_node);
        current_node.MapReduce.SubscribeTask(new MapReduceCache(current_node,_cs));
        current_node.MapReduce.SubscribeTask(new MapReduceCrawl(current_node));
	_c_node = current_node;
      }
      else {
        _q_dht = new Dht(current_node, 3, 20);
	CacheList q_cs = new CacheList(current_node);
        current_node.MapReduce.SubscribeTask(new MapReduceQuery(current_node,_cs));
        current_node.MapReduce.SubscribeTask(new MapReduceCrawl(current_node));
	_q_node = current_node;
      }

    }
 //private Node _node;
 /*
  * @param cl CacheList object for caching.
  */
 public MapReduceCache(Node n, CacheList cl): base(n) {
   //_node = n;
   _cl = cl;
 }