|
@@ -27,11 +27,11 @@ class VanillaCreatedExtendedHandler:
|
|
|
circhandler.add_crypt_layer(enckey, deckey)
|
|
|
if len(circhandler.circuit_descs) == 0:
|
|
|
# This was a VanillaCreatedCircuitCell
|
|
|
- circhandler.replace_celltype_handler( \
|
|
|
+ circhandler.replace_celltype_handler(
|
|
|
relay.VanillaCreatedCircuitCell, None)
|
|
|
else:
|
|
|
# This was a VanillaExtendedCircuitCell
|
|
|
- circhandler.replace_celltype_handler( \
|
|
|
+ circhandler.replace_celltype_handler(
|
|
|
relay.VanillaExtendedCircuitCell, None)
|
|
|
circhandler.circuit_descs.append(self.expecteddesc)
|
|
|
|
|
@@ -42,7 +42,7 @@ class VanillaCreatedExtendedHandler:
|
|
|
|
|
|
nexthop = None
|
|
|
while nexthop is None:
|
|
|
- nexthop = self.channelmgr.consensus.select_weighted_relay( \
|
|
|
+ nexthop = self.channelmgr.consensus.select_weighted_relay(
|
|
|
self.channelmgr.consensus_cdf)
|
|
|
if nexthop.descdict['addr'] in \
|
|
|
[ desc.descdict['addr'] \
|
|
@@ -52,12 +52,12 @@ class VanillaCreatedExtendedHandler:
|
|
|
# Construct the VanillaExtendCircuitCell
|
|
|
ntor = relay.NTor(self.channelmgr.perfstats)
|
|
|
ntor_request = ntor.request()
|
|
|
- circextendmsg = relay.VanillaExtendCircuitCell( \
|
|
|
+ circextendmsg = relay.VanillaExtendCircuitCell(
|
|
|
nexthop.descdict['addr'], ntor_request)
|
|
|
|
|
|
# Set up the reply handler
|
|
|
- circhandler.replace_celltype_handler( \
|
|
|
- relay.VanillaExtendedCircuitCell, \
|
|
|
+ circhandler.replace_celltype_handler(
|
|
|
+ relay.VanillaExtendedCircuitCell,
|
|
|
VanillaCreatedExtendedHandler(self.channelmgr, ntor, nexthop))
|
|
|
|
|
|
# Send the cell
|
|
@@ -122,8 +122,8 @@ class ClientChannelManager(relay.ChannelManager):
|
|
|
circcreatemsg = relay.VanillaCreateCircuitMsg(circid, ntor_request)
|
|
|
|
|
|
# Set up the reply handler
|
|
|
- circhandler.replace_celltype_handler( \
|
|
|
- relay.VanillaCreatedCircuitCell, \
|
|
|
+ circhandler.replace_celltype_handler(
|
|
|
+ relay.VanillaCreatedCircuitCell,
|
|
|
VanillaCreatedExtendedHandler(self, ntor, self.guard))
|
|
|
|
|
|
# Send the message
|
|
@@ -140,8 +140,9 @@ class ClientChannelManager(relay.ChannelManager):
|
|
|
"""Callback when a NetMsg not specific to a circuit is
|
|
|
received."""
|
|
|
print("Client %s received msg %s from %s" % (self.myaddr, msg, peeraddr))
|
|
|
- if isinstance(msg, relay.RelayConsensusMsg):
|
|
|
- dirauth.Consensus.verify(msg.consensus, \
|
|
|
+ if isinstance(msg, relay.RelayConsensusMsg) or \
|
|
|
+ instance(msg, relay.RelayConsensusDiffMsg):
|
|
|
+ dirauth.Consensus.verify(msg.consensus,
|
|
|
network.thenetwork.dirauthkeys(), self.perfstats)
|
|
|
self.consensus = msg.consensus
|
|
|
if network.thenetwork.womode == network.WOMode.VANILLA:
|
|
@@ -188,7 +189,23 @@ class Client:
|
|
|
# we'll need a consensus (uh, oh; in that case, fetch the
|
|
|
# consensus from a fallback relay).
|
|
|
|
|
|
- self.channelmgr.get_consensus_from_fallbackrelay()
|
|
|
+ guardaddr = self.channelmgr.guardaddr
|
|
|
+ guardchannel = None
|
|
|
+ if guardaddr is not None:
|
|
|
+ try:
|
|
|
+ guardchannel = self.channelmgr.get_channel_to(guardaddr)
|
|
|
+ except network.NetNoServer:
|
|
|
+ guardaddr = None
|
|
|
+
|
|
|
+ if guardchannel is None:
|
|
|
+ self.channelmgr.get_consensus_from_fallbackrelay()
|
|
|
+ else:
|
|
|
+ if self.channelmgr.consensus is not None and \
|
|
|
+ len(self.channelmgr.consensus.consdict['relays']) > 0:
|
|
|
+ guardchannel.send_msg(relay.RelayGetConsensusDiffMsg())
|
|
|
+ else:
|
|
|
+ guardchannel.send_msg(relay.RelayGetConsensusMsg())
|
|
|
+
|
|
|
print('client consensus=', self.channelmgr.consensus)
|
|
|
|
|
|
def newepoch(self, epoch):
|
|
@@ -288,10 +305,10 @@ if __name__ == '__main__':
|
|
|
r = clients[0].channelmgr.consensus.select_weighted_relay(clients[0].channelmgr.consensus_cdf)
|
|
|
print("relay",r.descdict["addr"])
|
|
|
|
|
|
- relays[3].terminate()
|
|
|
- relaysent += relays[3].perfstats.bytes_sent
|
|
|
- relayrecv += relays[3].perfstats.bytes_received
|
|
|
- del relays[3]
|
|
|
+ #relays[3].terminate()
|
|
|
+ #relaysent += relays[3].perfstats.bytes_sent
|
|
|
+ #relayrecv += relays[3].perfstats.bytes_received
|
|
|
+ #del relays[3]
|
|
|
|
|
|
# Tick the epoch
|
|
|
network.thenetwork.nextepoch()
|
|
@@ -302,6 +319,9 @@ if __name__ == '__main__':
|
|
|
circs.append(circ)
|
|
|
circ.send_cell(relay.StringCell("hello world circuit %d" % i))
|
|
|
|
|
|
+ # Tick the epoch
|
|
|
+ network.thenetwork.nextepoch()
|
|
|
+
|
|
|
# See what channels exist and do a consistency check
|
|
|
for r in relays:
|
|
|
print("%s: %s" % (r.netaddr, [ str(k) + str([ck for ck in r.channelmgr.channels[k].circuithandlers.keys()]) for k in r.channelmgr.channels.keys()]))
|