- 016F72E7FD06B003916FCD423F9AB0155A912B421064D440823AA37D96F532E325120A93308278921F984C6BD5D4E8E887124370059C2D295D2F23FD1F7903E8
+ 851FE9967EA2562F0BD30255F3E9B1CA1487E7FD56A649E93A0EFBA4D6DE28A70F0FF6C1B3DDBEF90EE4D6370403D18A27A31CDCD062A46E7116DB5F4479F7A3
blatta/lib/server.py
(1 . 4)(1 . 4)
105 VERSION = "9993"
106 VERSION = "9992"
107
108 import os
109 import select
(142 . 47)(142 . 51)
111 del self.channels[irc_lower(channel.name)]
112
113 def handle_udp_data(self, bytes_address_pair):
114 data = bytes_address_pair[0]
115 address = bytes_address_pair[1]
116 for peer in self.state.get_peers():
117 data = bytes_address_pair[0]
118 address = bytes_address_pair[1]
119 message = self.infosec.unpack(peer, data)
120 if(message != None):
121 self.print_debug("valid message from peer: %s" % peer.handles[0])
122
123 # we only update the address table if the speaker is same as peer
124
125 try:
126 idx = peer.handles.index(message["speaker"])
127 except:
128 idx = None
129
130 if idx != None:
131 self.state.update_address_table({"handle": message["speaker"],
132 "address": address[0],
133 "port": address[1]
134 })
135 # send the message to all clients
136 for c in self.clients:
137 # self.clients[c].udp_socket_readable_notification(message)
138 if (self.clients[c].is_addressed_to_me(message["body"])):
139 self.clients[c].message(message["body"])
140 # send the message to all other peers if it should be propagated
141 if(message["command"] == BROADCAST) and message["bounces"] < MAX_BOUNCES:
142 self.rebroadcast(peer, message)
143 return
144 if peer.get_key() != None:
145 message = self.infosec.unpack(peer, data)
146 if(message != None):
147 self.print_debug("valid message from peer: %s" % peer.handles[0])
148
149 # we only update the address table if the speaker is same as peer
150
151 try:
152 idx = peer.handles.index(message["speaker"])
153 except:
154 idx = None
155
156 if idx != None:
157 self.state.update_address_table({"handle": message["speaker"],
158 "address": address[0],
159 "port": address[1]
160 })
161 # send the message to all clients
162 for c in self.clients:
163 # self.clients[c].udp_socket_readable_notification(message)
164 if (self.clients[c].is_addressed_to_me(message["body"])):
165 self.clients[c].message(message["body"])
166 # send the message to all other peers if it should be propagated
167 if(message["command"] == BROADCAST) and message["bounces"] < MAX_BOUNCES:
168 self.rebroadcast(peer, message)
169 return
170 self.print_debug("Unknown peer: %s %d" % (address[0], address[1]))
171
172 def peer_message(self, message):
173 message["original"] = True
174 if message["command"] == DIRECT:
175 peer = self.state.get_peer_by_handle(message["handle"])
176 if peer:
177 if peer and (peer.get_key() != None):
178 peer.send(message)
179 else:
180 self.print_debug("Discarding message to unknown handle: %s" % message["handle"])
181 self.print_debug("Discarding message to unknown handle or handle with no key: %s" % message["handle"])
182 else:
183 for peer in self.state.get_peers():
184 peer.send(message)
185 if peer.get_key() != None:
186 peer.send(message)
187 else:
188 self.print_debug("Discarding message to handle with no key: %s" % message["handle"])
189
190 def rebroadcast(self, source_peer, message):
191 message["original"] = False