Skip to content

Commit

Permalink
Search bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Musuvathy Santharam committed Apr 25, 2016
1 parent f1a83ca commit 6ca0bc6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
8 changes: 5 additions & 3 deletions ProtocolHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def parse_response(self, data):
r'(?<=JOIN)(?P<join_resp>OK) (?P<error_code_join>-?\d+)|' \
r'(?<=LEAVE) (?P<address_leave>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s+\d+)|' \
r'(?<=LEAVE)(?P<leave_resp>OK) (?P<error_code_leave>-?\d+)|' \
r'(?<=SER) (?P<address_search>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} \d+) (?P<ser_key>[a-zA-Z0-9_]+)|' \
r'(?<=SER) (?P<ser_req_starttime>\d+) (?P<ser_req_hops>\d+) (?P<address_search>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} \d+) (?P<ser_key>[a-zA-Z0-9_]+)|' \
r'(?<=SER)(?P<ser_resp>OK) (?P<ser_starttime>\d+) (?P<ser_hops>\d+) (?P<ser_count>\d+) (?P<ser_resp_details> *\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} \d+ [0-9a-zA-Z_]+)|' \
r'(?<=UPFIN) (?P<upfin_type>[01]) (?P<upfin_node_address>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} \d+) (?P<ip_hash>[A-Za-z0-9\-]+)|' \
r'(?<=UPFIN)(?P<upfin_resp>OK) (?P<error_code_upfin>-?\d+)|' \
Expand Down Expand Up @@ -117,8 +117,8 @@ def parse_response(self, data):
for ip, port, key in response['details']:
details.append(((ip, port), key))
response['details'] = details
response['starttime'] = response_validate.groups('ser_starttime')
response['hops'] = response_validate.groups('ser_hops')
response['starttime'] = response_validate.group('ser_starttime')
response['hops'] = response_validate.group('ser_hops')
response['error_code'] = int(response_validate.group('ser_count'))

else:
Expand All @@ -129,6 +129,8 @@ def parse_response(self, data):
'address_search') is not None else '')
response['address'] = self.format_addresses(response['address'])
response['key'] = response_validate.group('ser_key')
response['starttime'] = response_validate.group('ser_req_starttime')
response['hops'] = response_validate.group('ser_req_hops')
elif response_type == 'UPFIN':
response['type'] = response_type
if response_validate.group('upfin_resp') == 'OK':
Expand Down
13 changes: 6 additions & 7 deletions central_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import re
import json
from time import strftime, gmtime
from utilities import resources


b_ip = None
Expand Down Expand Up @@ -113,14 +112,14 @@ def __send_command(self, ip, port, command, rx=False):
self.client_skt.close()
self.client_skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
self.client_skt.connect((toip, int(toport)))
self.client_skt.connect((ip, int(port)))
except socket.error, e:
print e.message
self.client_skt.close()
self.client_skt = None
return

self.client_skt.send(message)
self.client_skt.send(command)
return_message = "NONE"
if rx == True:
try:
Expand Down Expand Up @@ -155,9 +154,9 @@ def fake_register(self):
def search_for(self, query):
node = self.random_node()
if node is not None:
command = {'command':'STARTSEARCH', 'QUERY':entry, 'SERVERINFO':(self.myip, self.myport)}
command = {'command':'STARTSEARCH', 'QUERY':query, 'SERVERINFO':(self.myip, self.myport)}
self.__send_command(node[0], node[1], json.dumps(command))
self.write_log("STARTSEARCH " + entry + "=> " + str(node[0]) + ":" + str(node[1]))
self.write_log("STARTSEARCH " + query + "=> " + str(node[0]) + ":" + str(node[1]))
self.__main_thread_notifier.wait(3)
self.__main_thread_notifier.clear()
return True
Expand Down Expand Up @@ -236,7 +235,7 @@ def display(self, ip, port, arg):
def write_log(self, data):
cur_time = strftime("[%m-%d %H:%M:%S]", gmtime())
msg = "{0}: {1}".format(cur_time, data)
f.write(msg + '\n')
self.__logfile.write(msg + '\n')



Expand Down Expand Up @@ -310,7 +309,7 @@ def main():
for f in freq:
r = range(f)
query = resources[idx]
for i in range(r):
for i in r:
controller.search_for(query)
idx += 1

Expand Down
16 changes: 11 additions & 5 deletions peer
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ def handler(data, sock, *args, **kwargs):
if data.get('command') == 'EXITALL':
node.stop()
elif data.get('command') == 'STARTSEARCH':
node.send_data(tuple(data['SERVERINFO']), time.time(), 0, protocol.search_request(node.get_address(), chord.generate_file_id(data['QUERY'])))
#node.send_data(tuple(data['SERVERINFO']), time.time(), 0, protocol.search_request(node.get_address(), chord.generate_file_id(data['QUERY'])))
node.send_data(tuple(data['SERVERINFO']), protocol.search_request(time.time(), 0, node.get_address(), chord.generate_file_id(data['QUERY'])))
elif data.get('command') == 'PICKRESOURCES':
files = select_random_files(read_resource_txt(secondary_list), data['num_entries'])
data = [(node.get_address(), (chord.generate_file_id(filex), filex)) for filex in files]
for addr, (key, filename) in data:
chord.peer_file_add(key, filename, addr)

@node.on('message')
def echoMessage(data, sock=None, address=None, *args, **kwargs):
Expand Down Expand Up @@ -146,11 +152,11 @@ def search(request, sock):
if id == key:
details.append((addr, filename))
if len(details) > 0:
node.send_data(request['address'], int(request['hops']) + 1, int(request['starttime']), time.time(),
protocol.search_response(details))
node.send_data(request['address'],
protocol.search_response(int(request['hops']) + 1,int(request['starttime']),time.time(),details))
else:
node.send_data(chord.get_max_dist_address(key), int(request['starttime']), int(request['hops']) + 1,
protocol.search_request(request['address'], key))
node.send_data(chord.get_max_dist_address(key),
protocol.search_request(int(request['starttime']), int(request['hops']) + 1, request['address'], key))


@node.on('UPFIN')
Expand Down

0 comments on commit 6ca0bc6

Please sign in to comment.