Merge lp:~aj00200/anonplus/trunk into lp:anonplus

Proposed by aj00200
Status: Merged
Merged at revision: 198
Proposed branch: lp:~aj00200/anonplus/trunk
Merge into: lp:anonplus
Diff against target: 241 lines (+76/-45)
5 files modified
src/libs/friends.py (+38/-36)
src/libs/packets.py (+9/-2)
src/libs/storage/classes.py (+8/-1)
src/tunnels/tor.py (+19/-5)
src/vomun.py (+2/-1)
To merge this branch: bzr merge lp:~aj00200/anonplus/trunk
Reviewer Review Type Date Requested Status
pharno Approve
Review via email: mp+89621@code.launchpad.net

Commit message

* Wrote code to handle the 0x0100 UUK Storage Request packet from the mock-storage-request blueprint.
* Updated libs.friends to use the Registrar which is setup by tunnels.__init__ instead of importing them manually.

Description of the change

Added some code for the mock-storage-implementation blueprint. Please make a note on the blueprint whiteboard if more work is needed on this.

To post a comment you must log in.
lp:~aj00200/anonplus/trunk updated
211. By aj00200

Moved code as per discussion on IRC. Also set up the start of the Tor tunnel. Also fixed the tunnel loading and listener starting.

Revision history for this message
pharno (pharno) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/libs/friends.py'
--- src/libs/friends.py 2012-01-15 16:14:19 +0000
+++ src/libs/friends.py 2012-01-24 22:43:26 +0000
@@ -6,7 +6,7 @@
6import time6import time
77
8import libs8import libs
9from tunnels import directudp, directudpv6, tor9import tunnels
10from libs.events import broadcast10from libs.events import broadcast
11import libs.encryption.rsa11import libs.encryption.rsa
12from libs.packets import parse_packets, packets_by_id, make_packet12from libs.packets import parse_packets, packets_by_id, make_packet
@@ -43,33 +43,6 @@
43 broadcast('logthis', 'Loading friend: %s\n%s' % (friend, error),43 broadcast('logthis', 'Loading friend: %s\n%s' % (friend, error),
44 level = 5)44 level = 5)
4545
46@register_with_api
47def save_friends():
48 '''Write ~/.vomun/friends.json'''
49 friendlistw = open(friendlistpath, 'w+')
50 json_template = '''[
51%s
52]'''
53 friendsjson = ','.join([friend._json() for friend in libs.globals['friends'].values()])
54 friendlistw.write(json_template % friendsjson)
55 friendlistw.flush()
56
57@register_with_api
58def add_friend(keyid, ip, port, name, tunnel):
59 '''Add a friend to our friends list'''
60 friend_obj = Friend(keyid, ip, port, name, tunnel)
61 libs.globals['friends'][keyid] = friend_obj
62 save_friends()
63
64@register_with_api
65def del_friend(keyid):
66 '''Delete a friend'''
67 try:
68 del libs.globals['friends'][keyid]
69 except:
70 broadcast('logthis', 'Friend %s does not exist.' % keyid)
71
72
73class Friend:46class Friend:
74 '''Friend class, stores data related to a friend such as the Connection47 '''Friend class, stores data related to a friend such as the Connection
75 object and the encryption object. Handles data transfer and encryption.48 object and the encryption object. Handles data transfer and encryption.
@@ -84,9 +57,15 @@
84 57
85 # Set default values.58 # Set default values.
86 self.connected = False59 self.connected = False
87 self.rconnection = None
88 self.wconnection = None
89 self.data = ''60 self.data = ''
61
62 # Setup Tunnel
63 if self.tunnel_type == 'directudp':
64 self.wconnection = tunnels.registered['directudp'].Tunnel(self)
65 elif self.tunnel_type == 'directudpv6':
66 self.wconnection = tunnels.registered['directudpv6'].Tunnel(self)
67 elif self.tunnel_type == 'tor':
68 self.wconnection = tunnels.registered['tor'].Tunnel(self)
9069
91 # Setup encryption.70 # Setup encryption.
92 broadcast('logthis', 'Setting up encryption. %s:%s' % (71 broadcast('logthis', 'Setting up encryption. %s:%s' % (
@@ -130,6 +109,9 @@
130 elif packet_id == 'Message':109 elif packet_id == 'Message':
131 broadcast('got_message', packet)110 broadcast('got_message', packet)
132111
112 elif packet_id == 'UUKStorageRequest':
113 broadcast('uuk_storage_request', packet)
114
133 else:115 else:
134 print(packet_id, packet)116 print(packet_id, packet)
135117
@@ -147,12 +129,6 @@
147129
148 def connect(self):130 def connect(self):
149 '''Connect to the friend'''131 '''Connect to the friend'''
150 if self.tunnel_type == 'directudp':
151 self.wconnection = directudp.Tunnel(self)
152 elif self.tunnel_type == 'directudpv6':
153 self.wconnection = directudpv6.Tunnel(self)
154 elif self.tunnel_type == 'tor':
155 self.wconnection = tor.Tunnel(self)
156 self.wconnection.connect()132 self.wconnection.connect()
157133
158 def send(self, data, system=0):134 def send(self, data, system=0):
@@ -260,3 +236,29 @@
260 friend = get_friend_by_name(friend)236 friend = get_friend_by_name(friend)
261 friend.connect()237 friend.connect()
262 friend._begin_handshake()238 friend._begin_handshake()
239
240@register_with_api
241def save_friends():
242 '''Write ~/.vomun/friends.json'''
243 friendlistw = open(friendlistpath, 'w+')
244 json_template = '''[
245%s
246]'''
247 friendsjson = ','.join([friend._json() for friend in libs.globals['friends'].values()])
248 friendlistw.write(json_template % friendsjson)
249 friendlistw.flush()
250
251@register_with_api
252def add_friend(keyid, ip, port, name, tunnel):
253 '''Add a friend to our friends list'''
254 friend_obj = Friend(keyid, ip, port, name, tunnel)
255 libs.globals['friends'][keyid] = friend_obj
256 save_friends()
257
258@register_with_api
259def del_friend(keyid):
260 '''Delete a friend'''
261 try:
262 del libs.globals['friends'][keyid]
263 except:
264 broadcast('logthis', 'Friend %s does not exist.' % keyid)
263\ No newline at end of file265\ No newline at end of file
264266
=== modified file 'src/libs/packets.py'
--- src/libs/packets.py 2011-11-03 00:17:29 +0000
+++ src/libs/packets.py 2012-01-24 22:43:26 +0000
@@ -4,6 +4,7 @@
4DUMP_ALL_PACKETS = False4DUMP_ALL_PACKETS = False
55
6packets = {6packets = {
7 # 0x0000 - 0x00ff
7 0: Struct('ConnectionRequest',8 0: Struct('ConnectionRequest',
8 Enum(UBInt32('encryptionmethod'),9 Enum(UBInt32('encryptionmethod'),
9 rsa=0,10 rsa=0,
@@ -34,7 +35,13 @@
34 UBInt32('timestamp'),35 UBInt32('timestamp'),
35 UBInt32('message_length'),36 UBInt32('message_length'),
36 MetaField('message', lambda ctx: ctx['message_length'])37 MetaField('message', lambda ctx: ctx['message_length'])
37 ) 38 ),
39
40 # 0x0100 - 0x01ff
41 256: Struct('UUKStorageRequest',
42 UBInt32('data_length'),
43 MetaField('data', lambda ctx: ctx['data_length'])
44 )
38 45
39}46}
4047
@@ -101,4 +108,4 @@
101 print('Parsed packet %d' % packet[0])108 print('Parsed packet %d' % packet[0])
102 print(packet[1])109 print(packet[1])
103110
104 return l, leftovers
105\ No newline at end of file111\ No newline at end of file
112 return l, leftovers
106113
=== modified file 'src/libs/storage/classes.py'
--- src/libs/storage/classes.py 2011-12-05 22:51:42 +0000
+++ src/libs/storage/classes.py 2012-01-24 22:43:26 +0000
@@ -75,6 +75,13 @@
75 message = packet.message75 message = packet.message
76 self.add_uuk(Block(message))76 self.add_uuk(Block(message))
7777
78 def uuk_storage_request(self, packet):
79 '''Received a packet requesting that we store the included data.
80 As per the mock-storage-implementation blueprint, we will store
81 this data, no questions asked. There is no limits.
82 '''
83 self.add_uuk(Block(packet.data))
84
78 def got_request(self, query):85 def got_request(self, query):
79 '''Got a request for a data block.'''86 '''Got a request for a data block.'''
80 self.search(query)87 self.search(query)
@@ -88,4 +95,4 @@
88 network for the requested data.'''95 network for the requested data.'''
89 def __init__(self, blocktype, id):96 def __init__(self, blocktype, id):
90 self.type = blocktype97 self.type = blocktype
91 self.id = id
92\ No newline at end of file98\ No newline at end of file
99 self.id = id
93100
=== modified file 'src/tunnels/tor.py'
--- src/tunnels/tor.py 2012-01-08 22:19:56 +0000
+++ src/tunnels/tor.py 2012-01-24 22:43:26 +0000
@@ -1,5 +1,5 @@
1'''Tunnel to use to connect to other nodes over tor.'''1'''Tunnel to use to connect to other nodes over Tor.'''
2import libs.socks2import socks
3import libs.threadmanager3import libs.threadmanager
44
5class Tunnel(object):5class Tunnel(object):
@@ -17,14 +17,23 @@
17 def disconnect(self, nodeid):17 def disconnect(self, nodeid):
18 '''Disconnect from a node at `nodeid`'''18 '''Disconnect from a node at `nodeid`'''
19 pass19 pass
20
21 def send(self, message):
22 self.connection.send(message)
2023
21class Connection(object):24class Connection(object):
22 '''A class to store a connection to a peer'''25 '''A class to store a connection to a peer'''
23 def __init__(self, node):26 def __init__(self, node):
24 self.sock = libs.socks.socksocket()27 self.sock = socks.socksocket()
25 self.sock.setproxy(libs.socks.PROXY_TYPE_SOCKS5, addr='localhost',28 self.sock.setproxy(socks.PROXY_TYPE_SOCKS5, addr='localhost',
26 port=9050, rdns=True)29 port=9050, rdns=True)
27 self.sock.connect((node.ip, node.port))30 # node.ip must not be unicode because of this bug in python-socks:
31 # https://code.google.com/p/httplib2/issues/detail?id=179
32 self.sock.connect((str(node.ip), node.port))
33
34 def send(self, message):
35 broadcast('logthis', 'Sending: ' + message, level = 0)
36 self.sock.send(message)
2837
29class Listener(libs.threadmanager.Thread):38class Listener(libs.threadmanager.Thread):
30 '''A class to listen for connections sent to our Tor onion address.39 '''A class to listen for connections sent to our Tor onion address.
@@ -44,3 +53,8 @@
44 # TODO: find out which friend this is without IP address53 # TODO: find out which friend this is without IP address
45 connection = self.sock.accept() # TODO: this blocks!!!!!54 connection = self.sock.accept() # TODO: this blocks!!!!!
46 # TODO: convert this connection to a Connection object!!55 # TODO: convert this connection to a Connection object!!
56
57def start():
58 listener = Listener()
59 listener.start()
60 libs.threadmanager.register(listener)
47\ No newline at end of file61\ No newline at end of file
4862
=== modified file 'src/vomun.py'
--- src/vomun.py 2012-01-21 05:29:37 +0000
+++ src/vomun.py 2012-01-24 22:43:26 +0000
@@ -13,8 +13,9 @@
13def start():13def start():
14 morado.start()14 morado.start()
15 friends.load_friends()15 friends.load_friends()
16 tunnels.directudp.start()
17 storage.manager.start()16 storage.manager.start()
17 for tunnel in tunnels.registered:
18 tunnels.registered[tunnel].start()
1819
19 uis.web.manager.start()20 uis.web.manager.start()
20 atexit.register(cleanup)21 atexit.register(cleanup)

Subscribers

People subscribed via source and target branches

to all changes: