/// <summary>True upon a non-revoked certificate, an exception otherwise.</summary> public bool Verify(X509Certificate x509, Brunet.Messaging.ISender sender) { Certificate cert = new Certificate(x509.RawData); if(!_revoked_users.Contains(cert.Subject.Name)) { return true; } throw new Exception("User has been revoked!"); }
/** * Injects the binary data into the system. * @param assembly_data pre-compiled data that will be injected into the * system. */ protected void Inject(Brunet.Util.MemBlock assembly_data) { Assembly ass = Assembly.Load(assembly_data); Type[] types = ass.GetTypes(); foreach(Type type in types) { ass.CreateInstance(type.ToString(), false, BindingFlags.CreateInstance, null, new object[1] {_node}, null, null); } }
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; }
/// <summary>Receive data from the remote end point.</summary> public void Push(Brunet.Util.MemBlock p) { if( 1 == _is_closed ) { return; } if(Delay > 0) { var timer = new Brunet.Util.SimpleTimer(DelayedPush, p, Delay, 0); timer.Start(); } else { ReceivedPacketEvent(p); } }
public BrunetDhtEntry(byte[] key, Brunet.DistributedServices.DhtGetResult dgr) : this(key, dgr.value, dgr.age, dgr.ttl) { }
/** <summary>Begins a new transfer state to the neighbor connected via con. </summary> <param name="con">The connection to the neigbhor we will be transferring data to.</param> <param name="ts">The table server we're providing the transfer for. C# does not allow sub-class objects to have access to their parent objects member variables, so we pass it in like this.</param> <remarks> Step 1: Get all the keys between me and my new neighbor. Step 2: Get all values for those keys, we copy so that we don't worry about changes to the dht during this interaction. This is only a pointer copy and since we let the OS deal with removing the contents of an entry, we don't need to make copies of the actual entry. Step 3: Generate another list of keys of up to max parallel transfers and begin transferring, that way we do not need to lock access to the entry enumerator until non-constructor puts. Step 4: End constructor, results from puts, cause the next entry to be sent. */ public TransferState(Brunet.Connections.Connection con, TableServer ts) { this._ts = ts; this._con = con; // Get all keys between me and my new neighbor LinkedList<MemBlock> keys; lock(_ts._sync) { keys = _ts._data.GetKeysBetween((AHAddress) _ts._node.Address, (AHAddress) _con.Address); } if(Dht.DhtLog.Enabled) { ProtocolLog.Write(Dht.DhtLog, String.Format( "Starting transfer from {0} to {1}", _ts._node.Address, _con.Address)); } int total_entries = 0; /* Get all values for those keys, we copy so that we don't worry about * changes to the dht during this interaction. This is only a pointer * copy and since we let the OS deal with removing the contents of an * entry, we don't need to make copies of the actual entry. */ foreach(MemBlock key in keys) { Entry[] entries; lock(_ts._sync) { LinkedList<Entry> llentries = _ts._data.GetEntries(key); if(llentries == null) { continue; } entries = new Entry[llentries.Count]; total_entries += llentries.Count; llentries.CopyTo(entries, 0); } key_entries.AddLast(entries); } if(Dht.DhtLog.Enabled) { ProtocolLog.Write(Dht.DhtLog, String.Format( "Total keys: {0}, total entries: {1}.", key_entries.Count, total_entries)); } _entry_enumerator = GetEntryEnumerator(); /* Here we generate another list of keys that we would like to * this is done here, so that we can lock up the _entry_enumerator * only during this stage and not during the RpcManager.Invoke */ LinkedList<Entry> local_entries = new LinkedList<Entry>(); for(int i = 0; i < MAX_PARALLEL_TRANSFERS && _entry_enumerator.MoveNext(); i++) { local_entries.AddLast((Entry) _entry_enumerator.Current); } foreach(Entry ent in local_entries) { Channel queue = new Channel(); queue.CloseAfterEnqueue(); queue.CloseEvent += this.NextTransfer; int ttl = (int) (ent.EndTime - DateTime.UtcNow).TotalSeconds; try { _ts._rpc.Invoke(_con.Edge, queue, "dht.PutHandler", ent.Key, ent.Value, ttl, false); } catch { if(_con.Edge.IsClosed) { _interrupted = true; Done(); break; } } } }
public State UpdateReduce(Brunet.Util.Pair<object,bool> val, bool child_reduction) { //If we can, pop off a result which we need to reduce: ImmutableList<RpcResult> pend; bool reduce; bool done = Done || val.Second; int child_reds = ChildReductions; if( child_reduction ) { child_reds++; } if( false == Pending.IsEmpty && false == done ) { //More to reduce: pend = Pending.Tail; reduce = true; } else { pend = ImmutableList<RpcResult>.Empty; reduce = false; if( false == done ) { /* * Check to see if we have hit all our children * and we have already completed the map */ if( Tree != null ) { done = (child_reds == Tree.Length); } else { //We haven't yet gotten the Tree result back, done = false } } } return new State(MapResult, Tree, child_reds, val.First, done, pend, reduce); }
public void Send(Brunet.Util.ICopyable data) { State.Edge.Send(data); }
/** * @param peer_tid the TID that our Peer is using * @param local_tid the TID that we use for this Request * @param peer the peer Node in this transfer * @param read_from the stream to read the data from */ public Request(short peer_tid, short local_tid, Opcode req_type, Brunet.Address peer, System.IO.Stream read_from) { }
public Request(short local_tid, short peer_tid, Opcode req_type, Brunet.Address peer, string filename, long tsize) { }
/** * This method is called when there is a change in a Connection's status */ protected void StatusChangedHandler(Connection c, Brunet.Collections.Pair<ConnectionState, ConnectionState> oldnew) { //Console.Error.WriteLine("Status Changed:\n{0}\n{1}\n{2}\n{3}",c, c.Status, nltarget, nrtarget); ConnectionList structs = _node.ConnectionTable.GetConnections(ConnectionType.Structured); ConnectToNearer(structs, c.Address, oldnew.Second.StatusMessage.Neighbors); }
public ChatEventArgs(ISender source, Brunet.Chat.Message m) { _source = source; _message = m; }
/** * The caller must make sure that this is synchronized, it is not * a thread-safe method * This method either writes the whole packet into the buffer space, * or it throws an exception. There is no other case. */ public void WriteToBuffer(Brunet.Util.ICopyable p) { int plength = p.CopyTo(_buffer, _written + 2); if( plength > Int16.MaxValue ) { throw new EdgeException(true, String.Format("Packet too long: {0}",plength)); } // //The length at the beginning: Brunet.Util.NumberSerializer.WriteShort((short)plength, _buffer, _written); //Also write the length at the end so we can detect a bad packet //as we have seen on planetlab: Brunet.Util.NumberSerializer.WriteShort((short)plength, _buffer, _written + 2 + plength); //If the buffer did not fill up, we have not yet thrown an exception: _written += (plength + 4); }