Example #1
0
        public void TestSend()
        {
            var fp = FragPipe.Instance;

            var head_c = new HeaderChop(new PType("frag").ToMemBlock());

            fp.Subscribe(head_c, null);

            var fh = new FragmentingHandler(1000);

            head_c.Subscribe(fh, null);

            var th = new TestHandler();

            fh.Subscribe(th, null);
            head_c.WithoutHeader.Subscribe(th, null);

            var fs = new FragmentingSender(100, fp);
            var r  = new System.Random();

            for (int length = 1; length < 10000; length++)
            {
                var buf = new byte[length];
                r.NextBytes(buf);
                var dat = MemBlock.Reference(buf);
                fs.Send(dat); //This will do the assert.
                Assert.AreEqual(dat, th.LastData, "Data was received");
            }
        }
Example #2
0
    /**
     * Create a node with a given local address and
     * a set of Routers.
     * @param addr Address for the local node
     * @param realm the Realm or Namespace this node belongs to
     */

    protected Node(Address addr, string realm)
    {
      //Start with the address hashcode:

      _sync = new Object();
      lock(_sync)
      {
        DemuxHandler = new DemuxHandler();
        /*
         * Make all the hashtables : 
         */
        _local_add = AddressParser.Parse( addr.ToMemBlock() );
        _realm = String.Intern(realm);
        
        /* Set up the heartbeat */
        _heart_period = 500; //500 ms, or 1/2 second.
        _heartbeat_handlers = new Dictionary<EventHandler, Brunet.Util.FuzzyEvent>();

        _task_queue = new NodeTaskQueue(this);
        _packet_queue = new BCon.LFBlockingQueue<IAction>();

        _running = 0;
        _send_pings = 1;

        //The default is pretty good, but add fallback handling of Relay:
        var erp = DefaultERPolicy.Create(Brunet.Relay.RelayERPolicy.Instance,
                                         addr,
                                         TransportAddress.TAType.S,
                                         TransportAddress.TAType.SO,
                                         TransportAddress.TAType.Function,
                                         TransportAddress.TAType.Udp,
                                         TransportAddress.TAType.Tcp,
                                         TransportAddress.TAType.Relay
                                        );
        _connection_table = new ConnectionTable(erp);
        _connection_table.ConnectionEvent += this.ConnectionHandler;

        //We start off offline.
        _con_state = Node.ConnectionState.Offline;
        
        /* Set up the ReqrepManager as a filter */
        _rrm = new ReqrepManager(this.ToString());
        DemuxHandler.GetTypeSource(PType.Protocol.ReqRep).Subscribe(_rrm, null);
        _rrm.Subscribe(this, null);
        this.HeartBeatEvent += _rrm.TimeoutChecker;
        /* Set up RPC */
        _rpc = new RpcManager(_rrm);
        DemuxHandler.GetTypeSource( PType.Protocol.Rpc ).Subscribe(_rpc, null);
        //Add a map-reduce handlers:
        _mr_handler = new MR.MapReduceHandler(this);
        //Subscribe it with the RPC handler:
        _rpc.AddHandler("mapreduce", _mr_handler);
        //Set up Fragmenting Handler:
        var fh = new FragmentingHandler(1024); //cache at most 1024 fragments
        DemuxHandler.GetTypeSource(
          FragmentingSender.FragPType ).Subscribe(fh, this);
        fh.Subscribe(this, fh);
        /*
         * Where there is a change in the Connections, we might have a state
         * change
         */
        _connection_table.ConnectionEvent += this.CheckForStateChange;
        _connection_table.DisconnectionEvent += this.CheckForStateChange;

#if !BRUNET_SIMULATOR
        _codeinjection = new Brunet.Services.CodeInjection(this);
        _codeinjection.LoadLocalModules();
#endif
        /*
         * We must later make sure the EdgeEvent events from
         * any EdgeListeners are connected to _cph.EdgeHandler
         */
        /**
         * Here are the protocols that every edge must support
         */
        /* Here are the transport addresses */
        _remote_ta = ImmutableList<TransportAddress>.Empty;
        /*@throw ArgumentNullException if the list ( new ArrayList()) is null.
         */
        /* EdgeListener's */
        _edgelistener_list = new ArrayList();
        _co_list = new List<ConnectionOverlord>();
        _edge_factory = new EdgeFactory();
        _ta_discovery = ImmutableList<Discovery>.Empty;
        StateChangeEvent += HandleTADiscoveryState;
        
        /* Initialize this at 15 seconds */
        _connection_timeout = new TimeSpan(0,0,0,0,15000);
        //Check the edges from time to time
        IAction cec_act = new HeartBeatAction(this, this.CheckEdgesCallback);
        _check_edges = Brunet.Util.FuzzyTimer.Instance.DoEvery(delegate(DateTime dt) {
          this.EnqueueAction(cec_act);
        }, 5000, 500);
      }
    }
Example #3
0
 public void TestSend() {
   var fp = FragPipe.Instance;
   
   var head_c = new HeaderChop(new PType("frag").ToMemBlock());
   fp.Subscribe(head_c, null);

   var fh = new FragmentingHandler(1000);
   head_c.Subscribe(fh, null);

   var th = new TestHandler();
   fh.Subscribe(th, null);
   head_c.WithoutHeader.Subscribe(th, null);

   var fs = new FragmentingSender(100, fp);
   var r = new System.Random();
   for(int length = 1; length < 10000; length++) {
     var buf = new byte[length];
     r.NextBytes(buf);
     var dat = MemBlock.Reference(buf);
     fs.Send(dat); //This will do the assert.
     Assert.AreEqual(dat, th.LastData, "Data was received");
   }
 }