public bool HandleReply(ReqrepManager man, ReqrepManager.ReqrepType rt, int mid, PType prot, MemBlock payload, ISender from, Brunet.ReqrepManager.Statistics s, object state) { Console.WriteLine("{0} got our message", from); return false; }
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 RpcResult(ISender ret_path, object res, ReqrepManager.Statistics stats) { _ret_path = ret_path; _result = res; _statistics = stats; }
/** * When an error comes in, this handles it */ public void HandleError(ReqrepManager man, int message_number, ReqrepManager.ReqrepError err, ISender ret_path, object state) { Exception x = null; RpcRequestState rs = (RpcRequestState) state; Channel bq = rs.Results; switch(err) { case ReqrepManager.ReqrepError.NoHandler: x = new AdrException(-32601, "No RPC Handler on remote host"); break; case ReqrepManager.ReqrepError.HandlerFailure: x = new AdrException(-32603, "The remote RPC System had a problem"); break; case ReqrepManager.ReqrepError.Timeout: //In this case we close the Channel: if( bq != null ) { bq.Close(); } break; case ReqrepManager.ReqrepError.Send: if( rs.RpcTarget is Edge ) { Edge e = (Edge)rs.RpcTarget; //This definitely won't get any more responses: if( e.IsClosed && bq != null ) { bq.Close(); } } //We had some problem sending, but ignore it for now break; } if( x != null && (bq != null) ) { RpcResult res = new RpcResult(ret_path, x); bq.Enqueue(res); } }
/** * Implements the IReplyHandler (also provides some light-weight statistics) */ public bool HandleReply(ReqrepManager man, ReqrepManager.ReqrepType rt, int mid, PType prot, MemBlock payload, ISender ret_path, ReqrepManager.Statistics statistics, object state) { RpcRequestState rs = (RpcRequestState) state; //ISender target = rs.RpcTarget; Channel bq = rs.Results; if( bq != null ) { object data = AdrConverter.Deserialize(payload); RpcResult res = new RpcResult(ret_path, data, statistics); bq.Enqueue(res); //Keep listening unless the queue is closed return (!bq.Closed); } else { //If they didn't even pass us a queue, I guess they didn't want to //listen too long return false; } }
public RpcManager(ReqrepManager rrm) { _sync = new Object(); _rrman = rrm; _method_cache = new Cache(CACHE_SIZE); _method_handlers = new Hashtable(); #if DAVID_ASYNC_INVOKE _rpc_command = new BlockingQueue(); _rpc_thread = new Thread(RpcCommandRun); _rpc_thread.IsBackground = true; _rpc_thread.Start(); #endif }
public void HandleError(ReqrepManager man, int message_number, ReqrepManager.ReqrepError err, ISender from, object state) { Console.WriteLine("Got Error from: {0}, {1}, {2}", from, message_number, err); }
public SecurityOverlord(RSACryptoServiceProvider rsa, ReqrepManager rrman, CertificateHandler ch) { _private_key = rsa; _private_key_lock = new object(); _ch = ch; _spi = new Dictionary<int, Dictionary<ISender, SecurityAssociation>>(); _cookie = new byte[CookieLength]; _rand = new Random(); _rand.NextBytes(_cookie); _rrman = rrman; _last_heartbeat = DateTime.UtcNow; _rrman.Subscribe(this, null); }
protected SecurityOverlord CreateInvalidSO(string name, int level) { if(rsa == null) { rsa = new RSACryptoServiceProvider(); byte[] blob = rsa.ExportCspBlob(false); RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider(); rsa_pub.ImportCspBlob(blob); CertificateMaker cm = new CertificateMaker("United States", "UFL", "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub, "brunet:node:abcdefghijklmnopqrs"); Certificate cert = cm.Sign(cm, rsa); x509 = cert.X509; } CertificateHandler ch = new CertificateHandler(); if(level == 2 || level == 0) { ch.AddCACertificate(x509); } if(level == 3 || level == 0) { ch.AddSignedCertificate(x509); } ReqrepManager rrm = new ReqrepManager("so" + name); _timeout += rrm.TimeoutChecker; SecurityOverlord so = new SecurityOverlord(rsa_safe, rrm, ch); so.AnnounceSA += AnnounceSA; RoutingDataHandler rdh = new RoutingDataHandler(); rrm.Subscribe(so, null); so.Subscribe(rdh, null); rdh.Subscribe(rrm, null); return so; }
/// <summary>If the request really failed, we'll have to close the SA.</summary> public void HandleError(ReqrepManager man, int message_number, ReqrepManager.ReqrepError err, ISender returnpath, object state) { if(man.RequestActive(message_number)) { return; } SecurityAssociation sa = state as SecurityAssociation; sa.Failure(); }
/// <summary>This better be a SecureControl message!</summary> public bool HandleReply(ReqrepManager man, ReqrepManager.ReqrepType rt, int mid, PType prot, MemBlock payload, ISender returnpath, ReqrepManager.Statistics statistics, object state) { if(!prot.Equals(SecureControl)) { return true; } bool done = false; try { HandleControl(payload, returnpath); } catch(Exception e) { ProtocolLog.WriteIf(ProtocolLog.Security, e.ToString()); done = true; } return done; }