public LocalDiscovery(ITAHandler ta_handler, string realm, RpcManager rpc, IPHandler iphandler) : base(ta_handler) { _rpc = rpc; _iphandler = iphandler; _realm = realm; _rpc.AddHandler(RPC_CLASS, this); }
public StructuredNode(AHAddress add, string realm):base(add,realm) { /** * Here are the ConnectionOverlords */ _leafco = new LeafConnectionOverlord(this); AddConnectionOverlord(_leafco); _snco = new StructuredNearConnectionOverlord(this); AddConnectionOverlord(_snco); _ssco = new StructuredShortcutConnectionOverlord(this); AddConnectionOverlord(_ssco); #if !BRUNET_SIMULATOR _iphandler = new IPHandler(); _iphandler.Subscribe(this, null); AddTADiscovery(new LocalDiscovery(this, Realm, _rpc, _iphandler)); #endif /** * Turn on some protocol support : */ /// Turn on Packet Forwarding Support : GetTypeSource(PType.Protocol.Forwarding).Subscribe(new PacketForwarder(this), null); AHHandler = new AHHandler(this); GetTypeSource(PType.Protocol.AH).Subscribe(AHHandler, this); GetTypeSource(PType.Protocol.Echo).Subscribe(new EchoHandler(), this); //Add the standard RPC handlers: _rpc.AddHandler("sys:ctm", new CtmRequestHandler(this)); sys_link = new ConnectionPacketHandler(this); _rpc.AddHandler("sys:link", sys_link); _rpc.AddHandler("trace", new TraceRpcHandler(this)); //Serve some public information about our ConnectionTable _rpc.AddHandler("ConnectionTable", new ConnectionTableRpc(ConnectionTable, _rpc)); //Add a map-reduce handlers: _mr_handler = new MapReduceHandler(this); //Subscribe it with the RPC handler: _rpc.AddHandler("mapreduce", _mr_handler); //Subscribe map-reduce tasks _mr_handler.SubscribeTask(new MapReduceTrace(this)); _mr_handler.SubscribeTask(new MapReduceRangeCounter(this)); /* * Handle Node state changes. */ StateChangeEvent += delegate(Node n, Node.ConnectionState s) { if( s == Node.ConnectionState.Leaving ) { //Start our StructuredNode specific leaving: Leave(); } }; _connection_table.ConnectionEvent += new EventHandler(this.EstimateSize); _connection_table.ConnectionEvent += new EventHandler(this.UpdateNeighborStatus); _connection_table.DisconnectionEvent += new EventHandler(this.EstimateSize); _connection_table.DisconnectionEvent += new EventHandler(this.UpdateNeighborStatus); }
public void Test() { IPAddress[] base_addresses = Dns.GetHostAddresses(string.Empty); ArrayList local_ips = new ArrayList(base_addresses); local_ips.Add(IPAddress.Loopback); ArrayList ips = new ArrayList(IPHandler.GetLocalIPAddresses()); foreach(IPAddress addr in local_ips) { Assert.IsTrue(ips.Contains(addr), addr + " is not in ips"); } Assert.AreEqual(ips.Count, local_ips.Count, "Count"); }
public BrunetRpc() { _rrm = new ReqrepManager("BrunetRpc"); _rrm.Subscribe(this, null); Rpc = new RpcManager(_rrm); IPHandler = new IPHandler(); IPHandler.Subscribe(this, null); _running = 1; _timer = new Thread(TimerThread); _timer.IsBackground = true; _timer.Start(); }
public BrunetRpc() { _rrm = new ReqrepManager("BrunetRpc"); _rrm.Subscribe(this, null); Rpc = new RpcManager(_rrm); IPHandler = new IPHandler(); IPHandler.Subscribe(this, null); _running = 1; _timer = new Thread(TimerThread); _timer.IsBackground = true; _timer.Start(); }
/** * <summary>Sends the data over the multicast socket.</summary> * <param name="data">The data to send.</summary> */ public override void Send(ICopyable data) { IPAddress[] ips = LocalIPAddresses; if (ips == null) { ips = IPHandler.GetLocalIPAddresses(); } // Silly users can trigger a handful of exceptions here... try { data = new CopyList(IPHandler.MagicCookie, data); byte[] buffer = new byte[data.Length]; int length = data.CopyTo(buffer, 0); // I REALLY HATE THIS but we can't be setting this option in more than one thread! lock (_s) { foreach (IPAddress ip in ips) { /* * This can throw an exception on an invalid address, we need to skip it and move on! * Never showed to be an issue in Linux, but Windows does some weird things. */ try { _s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, IPHandler.IPAddressToInt(ip)); } catch { continue; } _s.SendTo(buffer, 0, length, 0, EndPoint); } } } catch (System.Net.Sockets.SocketException sx) { throw new SendException(true, "SocketException", sx); } // Can't pass the fact that the IPHandler is not running :-/ catch (ObjectDisposedException odx) { throw new SendException(false, "Socket appears to be disposed", odx); } catch (Exception e) { ProtocolLog.WriteIf(ProtocolLog.Exceptions, "ERROR: " + e); throw new SendException(true, "Socket appears to be disposed", e); } }