コード例 #1
0
ファイル: messages.py プロジェクト: rpraveen/CollabMeet
def handle_heartbeat(strs):
  print "Received heartbeat.."
  instance.last_heartbeat_rcvd = time.time()
  if instance.is_master and instance.name != strs[instance.SENDER]:
    master.clear_master()
  instance.curr_master = strs[instance.SENDER]
  instance.nodes = []
  nodecount = int(strs[instance.NODECOUNT])
  for i in range(4, 4 + nodecount):
    s = strs[i]
    val = s.split('#')
    d = dict()
    d['name'] = val[0]
    d['password'] = val[1]
    d['ip'] = val[2]
    d['port'] = val[3]
    instance.nodes.append(config.Node(**d))
    if val[3] == '0':
      network.remove_peer(val[0])
  reply = "master:heartbeatreply"
  network.send(instance.curr_master, reply)
  video_name = strs[4 + nodecount]
  video_ip = strs[5 + nodecount]
  video_port = int(strs[6 + nodecount])
  for i in range(8 + nodecount, len(strs)):
    instance.chat_msgs += ":" + strs[i]
  api.update_video_source(video_name, video_ip, video_port)
コード例 #2
0
ファイル: master.py プロジェクト: balamark/CollabMeet
def send_heartbeats():
  data = gen_heartbeat_str()
  print "Sending heartbeats..", data
  for peer in network.get_connection_list():
    if peer not in instance.heartbeat_time:
      instance.heartbeat_time[peer] = time.time()
    if (time.time() - instance.heartbeat_time[peer]) >= instance.HEARTBEAT_TIMEOUT:
      print "Timeout: ", peer, "Current time: ", time.time(), "Last replied: ", instance.heartbeat_time[peer]
      #TODO: handle timeout
    else:
      network.send(peer, data)
  #print "Heartbeat reply times:", instance.heartbeat_time
  api.update_video_source(instance.curr_video_name, instance.curr_video_ip, instance.curr_video_port)