forked from cocagne/multi-paxos-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
36 lines (23 loc) · 1.07 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This module provides a very simple client interface for suggesting new
# replicated values to one of the servers. No reply is received so an eye must
# be kept on the server output to see if the new suggestion is received. Also,
# when master leases are in use, requests must be sent to the current master
# server. All non-master servers will ignore the requests since they do not have
# the ability to propose new values in the multi-paxos chain.
import sys
from twisted.internet import reactor, defer, protocol
import config
class ClientProtocol(protocol.DatagramProtocol):
def __init__(self, uid, new_value):
self.addr = config.peers[uid]
self.new_value = new_value
def startProtocol(self):
self.transport.write('propose {0}'.format(self.new_value), self.addr)
reactor.stop()
if len(sys.argv) != 3 or not sys.argv[1] in config.peers:
print 'python client.py <A|B|C> <new_value>'
sys.exit(1)
def main():
reactor.listenUDP(0,ClientProtocol(sys.argv[1], sys.argv[2]))
reactor.callWhenRunning(main)
reactor.run()