@@ -110,64 +110,70 @@ def admin(config):
110110 {'dog': 'black'}, {'tcp://192.168.1.34:5561': 'tcp://192.168.1.34:5556'})
111111 """
112112 response = encode_message (myinterfaces , config .data , config .peers )
113- log .debug ("dump request, responding {}" .format (response ))
113+ log .debug ("responding to dump request with {}" .format (response ))
114114 admin .send_string (response )
115+ continue
115116
116117 if command == "put" :
117- log .info ("performing a put of {}/{}" .format (key , value ))
118+ # log.info("performing a put of {}/{}".format(key, value))
118119 config .pub_queue .put ((key , value ))
119120 config .sub_queue .put (key )
120- response = "done"
121+ response = "{}/{} has been published" . format ( key , value )
121122 admin .send_string (response )
123+ continue
122124
123125 if command == "register" :
124- response = "registering {} {}" .format (key , value )
126+ config .peers [key ]= value
127+ response = "{}/{} has been registered" .format (key , value )
125128 log .info (response )
126129 admin .send_string (response )
127- config . peers [ key ] = value
130+ continue
128131
129132 if command == "sync" :
130133 """
131134 command = sync, key = None, value = <server to sync to>
132135 """
133- response = "ack sync to {}" .format (value )
134- log .debug (response )
135- admin .send_string (response )
136- log .debug ("opening connection to " + str (value ))
137- s2s_admin .connect (value )
138- command = ("('dump', '', '')" )
139- log .debug ("sending command " + command )
140- s2s_admin .send_string (command )
141- message = s2s_admin .recv_string ()
142- log .debug ("got " + str (message ) )
143- remote_ports , data , peers = eval (message )
144- # remote_admin, remote_pub = remote_ports
145- # config.peers[remote_admin] = remote_pub
146- # log.debug("remote_admin {}, remote_pub {}, data {}, peers {}".format(remote_admin, remote_pub, data, peers))
147- for topic in data :
148- log .debug ("subscribing to topic {}" .format (topic ))
149- config .sub_queue .put (topic )
150- s2s_admin .send_string ("('get', '{}', '')" .format (topic ))
151- message = s2s_admin .recv_string ()
152- log .debug ("queried key/value {}, got value {} from remote server" .format (topic , message ))
153- config .pub_queue .put ((topic , message ))
154- log .debug ("asking {} to register my addresses" .format (value ))
155- command = "('register', '{}', '{}')" .format (options .admin_interface , options .pub_interface )
156- log .debug ("sending: " + command )
157- s2s_admin .send_string (command )
158- message = s2s_admin .recv_string ()
159- # disabled since this will cause an infinite loop
160- # log.debug("asking {} to connect back to me ({})".format(value, options.admin_interface))
161- # s2s_admin.send_string("('link', None, '{}')".format(options.admin_interface))
136+ # response = "ack sync to {}".format(value)
137+ # log.debug(response)
138+ # admin.send_string(response)
139+ # log.debug("opening connection to " + str(value))
140+ # s2s_admin.connect(value)
141+ # command = ("('dump', '', '')")
142+ # log.debug("sending command " + command )
143+ # s2s_admin.send_string(command)
162144 # message = s2s_admin.recv_string()
163- log .debug ("got {}" .format (message ))
145+ # log.debug("got " + str(message) )
146+ # remote_ports, data, peers = eval(message)
147+ # # remote_admin, remote_pub = remote_ports
148+ # # config.peers[remote_admin] = remote_pub
149+ # # log.debug("remote_admin {}, remote_pub {}, data {}, peers {}".format(remote_admin, remote_pub, data, peers))
150+ # for topic in data:
151+ # log.debug("subscribing to topic {}".format(topic))
152+ # config.sub_queue.put(topic)
153+ # s2s_admin.send_string("('get', '{}', '')".format(topic))
154+ # message = s2s_admin.recv_string()
155+ # log.debug("queried key/value {}, got value {} from remote server".format(topic, message))
156+ # config.pub_queue.put((topic, message))
157+ # log.debug("asking {} to register my addresses".format(value))
158+ # command = "('register', '{}', '{}')".format(options.admin_interface, options.pub_interface)
159+ # log.debug("sending: " + command)
160+ # s2s_admin.send_string(command)
161+ # message = s2s_admin.recv_string()
162+ # # disabled since this will cause an infinite loop
163+ # # log.debug("asking {} to connect back to me ({})".format(value, options.admin_interface))
164+ # # s2s_admin.send_string("('link', None, '{}')".format(options.admin_interface))
165+ # # message = s2s_admin.recv_string()
166+ # log.debug("got {}".format(message))
167+ log .debug ("sync disabled for now" )
168+ continue
164169
165170 if command == "get" :
166171 """
167172 command = get, key = <key to get>, value = None
168173 """
169174 response = get_value (config , key )
170175 admin .send_string (response )
176+ continue
171177
172178 if command == "link" :
173179 """
@@ -190,9 +196,12 @@ def admin(config):
190196 #message = s2s_admin.recv_string()
191197 #log.debug("queried key/value {}, got value {} from remote server".format(topic, message))
192198 #config.pub_queue.put((topic, message))
193- log .debug ("asking {} to register my addresses" .format (value ))
199+ # log.debug("asking {} to register my addresses".format(value))
194200 message = s2s_admin ("register" , options .admin_interface , options .pub_interface , value )
195201 admin .send_string ("got {}" .format (message ))
202+ continue
203+
204+ command = ""
196205
197206
198207def get_value (config , key ):
@@ -214,7 +223,7 @@ def get_value(config, key):
214223 log .debug ("value not in local database, checking remote servers" )
215224 for server in config .peers :
216225 server_result = s2s_admin ("get" , key , "" , server )
217- log .debug ("querying server {} for {}" .format (server , key ))
226+ # log.debug("querying server {} for {}".format(server, key))
218227 if server_result :
219228 value = server_result
220229 log .info ("got value {}/{} from server {}" .format (key , value , server ))
@@ -228,7 +237,8 @@ def get_value(config, key):
228237 # stop as soon as we get a match
229238 log .debug ("terminating server search" )
230239 break
231- log .debug ("no remote servers, no matching entry" )
240+ else :
241+ log .debug ("no remote servers, no matching entry" )
232242 return value
233243
234244
@@ -285,6 +295,7 @@ def sub_subscriber(config):
285295 """
286296 context = zmq .Context ()
287297 sub = context .socket (zmq .SUB )
298+ sub .RCVTIMEO = 1000
288299 log .info ("sub_subscriber thread working" )
289300
290301 while True :
@@ -307,11 +318,14 @@ def sub_subscriber(config):
307318
308319 # check for subscriptions
309320 log .debug ("checking for subscriptions" )
310- subscription = sub .recv_string ()
311- key , value = subscription .split (" " , 1 )
312- # save value to the local database
313- config .set_value ( key , value )
314- log .info ("saved subsription {}/{} to local database" .format (key , value ))
321+ try :
322+ subscription = sub .recv_string ()
323+ key , value = subscription .split (" " , 1 )
324+ # save value to the local database
325+ config .set_value ( key , value )
326+ log .info ("saved subscription {}/{} to local database" .format (key , value ))
327+ except Exception as err :
328+ log .debug ("no subscrition activity, logged {}" .format (err ))
315329
316330def sub_poller (config ):
317331 """
0 commit comments