/** <summary>Creates an Information object for the node and type of service provider.</summary> <param name="node">The node where the service is to be provided</param> <param name="type">The name of the application providing service (example: BasicNode)</param> */ public Information(StructuredNode node, String type) { UserData = new Hashtable(); _type = type; _node = node; _rpc = node.Rpc; _rpc.AddHandler("Information", this); }
//Methods: protected PathELManager(EdgeListener el, bool thread) { _el = el; _sync = new object(); _edges = new List<Edge>(); _unannounced = new Dictionary<Edge, PathEdge>(); _pel_map = new Dictionary<string, PathEdgeListener>(); //Use the reqrep protocol with a special prefix: _rrm = new ReqrepManager("PathELManager:" + el.ToString(), PType.Protocol.Pathing); _rrm.Subscribe(this, null); Rpc = new RpcManager(_rrm); Rpc.AddHandler("sys:pathing", this); _el.EdgeEvent += HandleEdge; _running = true; _next_check = DateTime.UtcNow.Ticks; if(thread) { _timer_thread = new Thread( delegate() { while(_running) { Thread.Sleep(1000); TimeoutCheck(); } } ); _timer_thread.IsBackground = true; _timer_thread.Start(); } }
//Methods: protected PathELManager(EdgeListener el, bool thread) { _el = el; _sync = new object(); _edges = new List <Edge>(); _unannounced = new Dictionary <Edge, PathEdge>(); _pel_map = new Dictionary <string, PathEdgeListener>(); //Use the reqrep protocol with a special prefix: _rrm = new ReqrepManager("PathELManager:" + el.ToString(), PType.Protocol.Pathing); _rrm.Subscribe(this, null); Rpc = new RpcManager(_rrm); Rpc.AddHandler("sys:pathing", this); _el.EdgeEvent += HandleEdge; _running = true; _next_check = DateTime.UtcNow.Ticks; if (thread) { _timer_thread = new Thread( delegate() { while (_running) { Thread.Sleep(1000); TimeoutCheck(); } } ); _timer_thread.IsBackground = true; _timer_thread.Start(); } }
public LogManager(Node node) { Node = node; Rpc = node.Rpc; Rpc.AddHandler("LogManager", this); Console = new ConsoleTraceListener(true); }
/** * Installs the network coordinate service on a given node. * NCService instance can be installed on atmost one node. * Each node is allowed to have only one NCService instance. * @param node node for installing the service instance. * @param InitialPoint a starting place for the NCService to use */ public NCService(Node node, Point InitialPoint) { _sync = new object(); _node = null; _last_sample_instant = DateTime.MinValue; _samples = new Hashtable(); _vivaldi_state = new VivaldiState(); _vivaldi_state.WeightedError = INITIAL_WEIGHTED_ERROR; _vivaldi_state.Position = new Point(); _vivaldi_state.DistanceDelta = 0.0f; if (InitialPoint == null) { InitialPoint = new Point(); } _vivaldi_state.Position = InitialPoint; if (node != null) { _node = node; #if NC_DEBUG Console.Error.WriteLine("[NCService] {0} Starting an instance of NCService.", node.Address); #endif lock (_sync) { _rpc = _node.Rpc; _rpc.AddHandler("ncserver", this); _node.HeartBeatEvent += GetNextSample; } } }
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); }
/** * <summary>Creates an Information object for the node and type of service * provider.</summary> * <param name="node">The node where the service is to be provided</param> * <param name="type">The name of the application providing service (example: * BasicNode)</param> */ public Information(StructuredNode node, String type) { UserData = new Hashtable(); _type = type; _node = node; _rpc = node.Rpc; _rpc.AddHandler("Information", this); }
/// <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); }
/// <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); }
public SocialRpcHandler(StructuredNode node, SocialUser localUser, Dictionary <string, SocialUser> friends) { _node = node; _rpc = node.Rpc; _rpc.AddHandler("SocialVPN", this); _local_user = localUser; _friends = friends; }
/// <summary> /// The overloaded method for now is used to allow RpcManager to be replaced /// by MockRpcManager in unit tests. /// </summary> /// <param name="node"></param> /// <param name="rpc"></param> /// <param name="uri"></param> internal void Add(Node node, RpcManager rpc, string uri) { var xrm = new XmlRpcManager(node, rpc); lock (_sync_root) { // throw an exception if this mapping exists... _xrm_mappings.Add(node, xrm); RemotingServices.Marshal(xrm, uri); CheckAndSetDefaultManager(); } rpc.AddHandler("xmlrpc", xrm); }
/** * <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); }
public LocalConnectionOverlord(Node node) { _sync = new Object(); _allow_localcons = false; _active = false; _local_addresses = new List <AHAddress>(); _node = node; lock (_sync) { _rpc = node.Rpc; _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 SocialConnectionManager(SocialNode node, RpcManager rpc, SocialDnsManager sdm, SocialStatsManager ssm, SocialConfig config) { _rpc = rpc; _rpc.AddHandler(RPCID, this); _sdm = sdm; _node = node; _ssm = ssm; _networks = ImmutableDictionary <string, ISocialNetwork> .Empty; _fprs = ImmutableDictionary <string, string> .Empty; _times = ImmutableDictionary <string, DateTime> .Empty; _pending = ImmutableList <string> .Empty; _blocked = ImmutableList <string> .Empty; _beat_counter = 0; _auto_allow = config.AutoFriend; _sdm.Sender = this; #if !SVPN_NUNIT _timer = new Timer(TimerHandler, _beat_counter, PERIOD, PERIOD); LoadState(); #endif }
/** * The overloaded method for now is used to allow RpcManager to be replaced * by MockRpcManager in unit tests. */ public void Update(Node node, RpcManager rpc) { _rpc = rpc; _node = node; _xrm = new XmlRpcManager(_node, _rpc); _rpc.AddHandler("xmlrpc", _xrm); RemotingServices.Marshal(_xrm, "xm.rem"); }
/* <summary>Create a new set of chached data(For now, data is strings).</summary> * */ public CacheList(Node node) { _node = node; _rpc = RpcManager.GetInstance(node); ///add handler for deetoo data insertion and search. _rpc.AddHandler("Deetoo", new DeetooHandler(node,this)); }
public MRpcMTestReflection() { rpc = new MockRpcManager(); rpc.AddHandler("test", this); }
/** * The overloaded method for now is used to allow distinct Uri for multiple XmlRpcManagerServer. */ public void Update(Node node, string type) { RpcManager rpc = RpcManager.GetInstance(node); _rpc = rpc; _node = node; _xrm = new XmlRpcManager(_node, _rpc); _rpc.AddHandler("xmlrpc", _xrm); string svc_name = type + "xm.rem"; RemotingServices.Marshal(_xrm, svc_name); }
/** * Adds the instance as a RpcHandler under the name space "xmlrpc". */ public void AddAsRpcHandler() { _rpc.AddHandler("xmlrpc", this); }
/** * 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; _LOG = ProtocolLog.Monitor.Enabled; _connection_table = new ConnectionTable(new DefaultERPolicy(addr)); _connection_table.ConnectionEvent += this.ConnectionHandler; LockMgr = new ConnectionLockManager(_connection_table); //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); /* * 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); } }
public static void Main(string [] args) { if (args.Length < 1) { Console.WriteLine("please specify the number edge protocol."); Environment.Exit(0); } if (args.Length < 2) { Console.WriteLine("please specify the number of p2p nodes."); Environment.Exit(0); } if (args.Length < 3) { Console.WriteLine("please specify the number of missing edges."); Environment.Exit(0); } string proto = "function"; try { proto = args[0].Trim(); } catch (Exception) {} bool tunnel = false; int base_port = 54000; int network_size = Int32.Parse(args[1]); int missing_count = Int32.Parse(args[2]); try { tunnel = args[3].Trim().Equals("tunnel"); } catch (Exception) {} Console.WriteLine("use tunnel edges: {0}", tunnel); Random rand = new Random(); ArrayList missing_edges = new ArrayList(); for (int i = 0; i < missing_count; i++) { int idx = -1; int left, right; do { idx = rand.Next(0, network_size); left = (idx + 1) % network_size; if (idx == 0) { right = network_size - 1; } else { right = idx - 1; } } while (missing_edges.Contains(idx));// || //missing_edges.Contains(left) || //missing_edges.Contains(right)); Console.WriteLine("Will drop a left edge on idx {0}: ", idx); missing_edges.Add(idx); } // // Sort missing edges. // missing_edges.Sort(); SortedList dist = new SortedList(); // // Compute the average distance between missing edges. // if (missing_count > 1) { for (int i = 0; i < missing_count; i++) { int idx = (int)missing_edges[i]; int idx_next; int d; if (i == missing_count - 1) { idx_next = (int)missing_edges[0]; d = (network_size - 1) - idx + idx_next; } else { idx_next = (int)missing_edges[i + 1]; d = idx_next - idx - 1; } if (!dist.Contains(d)) { dist[d] = 0; } else { int c = (int)dist[d]; dist[d] = c + 1; } } } double sum = 0.0; int num = 0; Console.WriteLine("distribution of missing edges separation"); foreach (DictionaryEntry de in dist) { int k = (int)de.Key; int c = (int)de.Value; Console.WriteLine("{0} {1}", k, c); sum = sum + k * c; num = num + c; } Console.WriteLine("average separation: {0}", (double)sum / num); string brunet_namespace = "testing"; Console.WriteLine("Initializing..."); var RemoteTA = new List <TransportAddress>(); for (int i = 0; i < network_size; i++) { if (proto.Equals("udp")) { RemoteTA.Add(TransportAddressFactory.CreateInstance("brunet.udp://localhost:" + (base_port + i))); } else if (proto.Equals("function")) { RemoteTA.Add(TransportAddressFactory.CreateInstance("brunet.function://localhost:" + (base_port + i))); } } for (int i = 0; i < network_size; i++) { AHAddress address = new AHAddress(new RNGCryptoServiceProvider()); Node node = new StructuredNode(address, brunet_namespace); _sorted_node_list.Add((Address)address, node); _node_list.Add(node); RouteTestHandler test_handler = new RouteTestHandler(); node.GetTypeSource(new PType(routing_test)).Subscribe(test_handler, address.ToMemBlock()); RpcManager rpc_man = node.Rpc; rpc_man.AddHandler("rpc_routing_test", new RpcRoutingTestHandler(node)); } for (int i = 0; i < network_size; i++) { Node node = (Node)_sorted_node_list.GetByIndex(i); Console.WriteLine("Configuring node: {0} ", node.Address); TAAuthorizer ta_auth = null; if (missing_edges.Contains(i)) { int remote_port; if (i == network_size - 1) { remote_port = base_port; } else { remote_port = base_port + i + 1; } PortTAAuthorizer port_auth = new PortTAAuthorizer(remote_port); Console.WriteLine("Adding a port TA authorizer at: {0} for remote port: {1}", base_port + i, remote_port); ArrayList arr_tas = new ArrayList(); arr_tas.Add(port_auth); arr_tas.Add(new ConstantAuthorizer(TAAuthorizer.Decision.Allow)); ta_auth = new SeriesTAAuthorizer(arr_tas); } if (proto.Equals("udp")) { node.AddEdgeListener(new UdpEdgeListener(base_port + i, null, ta_auth)); } else if (proto.Equals("function")) { node.AddEdgeListener(new FunctionEdgeListener(base_port + i, -1.00, ta_auth)); } if (tunnel) { Console.WriteLine("Adding a tunnel edge listener"); node.AddEdgeListener(new Relay.RelayEdgeListener(node)); } _node_to_port[node] = base_port + i; node.RemoteTAs = RemoteTA; } //start nodes one by one. for (int i = 0; i < network_size; i++) { Node node = (Node)_node_list[i]; Console.WriteLine("Starting node: {0}, {1}", i, node.Address); node.Connect(); Console.WriteLine("Going to sleep for 2 seconds."); System.Threading.Thread.Sleep(2000); } //wait for 300000 more seconds Console.WriteLine("Going to sleep for 300000 seconds."); System.Threading.Thread.Sleep(300000); bool complete = CheckStatus(); int count = 0; // // Send a large number of packets as exact packets to random destinations // and make sure exact routing is perfect. // for (int i = 0; i < network_size; i++) { for (int j = 0; j < network_size; j++) { int src_idx = i; int dest_idx = j; Node src_node = (Node)_sorted_node_list.GetByIndex(src_idx); Node dest_node = (Node)_sorted_node_list.GetByIndex(dest_idx); //Console.WriteLine("{0} -> {1}", src_idx, dest_idx); Address dest_address = (Address)dest_node.Address; ISender s = new AHExactSender(src_node, dest_address); MemBlock p = dest_address.ToMemBlock(); s.Send(new CopyList(new PType(routing_test), p)); _sent++; //System.Threading.Thread.Sleep(10); s.Send(new CopyList(new PType(routing_test), p)); _sent++; //System.Threading.Thread.Sleep(10); } } //wait for 10 more seconds Console.WriteLine("Going to sleep for 10 seconds."); System.Threading.Thread.Sleep(10000); Console.WriteLine("Final statistics"); lock (_class_lock) { Console.WriteLine("Sent: {0}, Received: {1}, Wrongly routed: {2}", _sent, _received, _wrongly_routed); } int missing_rpcs = 0; int correct_rpcs = 0; int incorrect_rpcs = 0; Hashtable queue_to_address = new Hashtable(); for (int i = 0; i < network_size; i++) { for (int j = 0; j < network_size; j++) { int src_idx = i; int dest_idx = j; Node src_node = (Node)_sorted_node_list.GetByIndex(src_idx); Node dest_node = (Node)_sorted_node_list.GetByIndex(dest_idx); //Console.WriteLine("{0} -> {1}", src_idx, dest_idx); Address dest_address = (Address)dest_node.Address; ISender s = new AHExactSender(src_node, dest_address); RpcManager rpc_man = src_node.Rpc; Channel q = new Channel(); lock (_class_lock) { queue_to_address[q] = dest_address; } q.CloseAfterEnqueue(); q.CloseEvent += delegate(object o, EventArgs cargs) { lock (_class_lock) { Channel qu = (Channel)o; if (qu.Count == 0) { missing_rpcs++; } queue_to_address.Remove(qu); } }; q.EnqueueEvent += delegate(object o, EventArgs cargs) { lock (_class_lock) { Channel qu = (Channel)o; RpcResult rpc_reply = (RpcResult)qu.Peek(); byte [] result = (byte[])rpc_reply.Result; Address target = new AHAddress(result); if (target.Equals(queue_to_address[qu])) { correct_rpcs++; } else { incorrect_rpcs++; } } }; rpc_man.Invoke(s, q, "rpc_routing_test.GetIdentification", new object[] {}); } } //wait for 10 more seconds while (true) { int c = -1; lock (_class_lock) { c = incorrect_rpcs + missing_rpcs + correct_rpcs; } if (c < network_size * network_size) { Console.WriteLine("Going to sleep for 10 seconds."); System.Threading.Thread.Sleep(10000); } else { break; } } Console.WriteLine("Final statistics"); Console.WriteLine("correct rpcs: {0}, incorrect rpcs: {1}, missing rpcs: {2}", correct_rpcs, incorrect_rpcs, missing_rpcs); System.Environment.Exit(1); }
/** <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); }
/** * Installs the network coordinate service on a given node. * NCService instance can be installed on atmost one node. * Each node is allowed to have only one NCService instance. * @param node node for installing the service instance. * @param InitialPoint a starting place for the NCService to use */ public NCService(Node node, Point InitialPoint) { _sync = new object(); _node = null; _last_sample_instant = DateTime.MinValue; _samples = new Hashtable(); _vivaldi_state = new VivaldiState(); _vivaldi_state.WeightedError = INITIAL_WEIGHTED_ERROR; _vivaldi_state.Position = new Point(); _vivaldi_state.DistanceDelta = 0.0f; if(InitialPoint == null) { InitialPoint = new Point(); } _vivaldi_state.Position = InitialPoint; if(node != null) { _node = node; #if NC_DEBUG Console.Error.WriteLine("[NCService] {0} Starting an instance of NCService.", node.Address); #endif lock(_sync) { _rpc = _node.Rpc; _rpc.AddHandler("ncserver", this); _node.HeartBeatEvent += GetNextSample; } } }
public void Update(Node node, BrunetSecurityOverlord bso) { RpcManager rpc = RpcManager.GetInstance(node); _rpc = rpc; _node = node; _xrm = new XmlRpcManager(_node, _rpc, bso); _rpc.AddHandler("xmlrpc", _xrm); RemotingServices.Marshal(_xrm, "xm.rem"); }
public SocialConnectionManager(SocialNode node, RpcManager rpc, SocialDnsManager sdm, SocialStatsManager ssm, SocialConfig config) { _rpc = rpc; _rpc.AddHandler(RPCID, this); _sdm = sdm; _node = node; _ssm = ssm; _networks = ImmutableDictionary<string, ISocialNetwork>.Empty; _fprs = ImmutableDictionary<string, string>.Empty; _times = ImmutableDictionary<string, System.DateTime>.Empty; _pending = ImmutableList<string>.Empty; _blocked = ImmutableList<string>.Empty; _beat_counter = 0; _auto_allow = config.AutoFriend; _sdm.Sender = this; #if !SVPN_NUNIT _timer = new Timer(TimerHandler, _beat_counter, PERIOD, PERIOD); LoadState(); #endif }