def __init__(self): self.peers = [] for IP, port in config['raft']['cluster']: srv = ZeroMQPeer('%s:%s' % (IP, port), host=IP, port=port) self.peers.append(srv) if config['raft']['actor']: self.server = ZeroMQServer('%s:%s' % (config['IP'], config['raft']['port']), Follower(), [], self.peers, host=config['IP'], port=config['raft']['port']) self.server.start() self.client = ZeroMQClient(self.peers)
class LifeRaft(object): def __init__(self): self.peers = [] for IP, port in config['raft']['cluster']: srv = ZeroMQPeer('%s:%s' % (IP, port), host=IP, port=port) self.peers.append(srv) if config['raft']['actor']: self.server = ZeroMQServer('%s:%s' % (config['IP'], config['raft']['port']), Follower(), [], self.peers, host=config['IP'], port=config['raft']['port']) self.server.start() self.client = ZeroMQClient(self.peers) @property def value(self): return self.client.leader.split(':')
class LifeRaft(object): def __init__(self): self.peers = [] for IP, port in config["raft"]["cluster"]: srv = ZeroMQPeer("%s:%s" % (IP, port), host=IP, port=port) self.peers.append(srv) if config["raft"]["actor"]: self.server = ZeroMQServer( "%s:%s" % (config["IP"], config["raft"]["port"]), Follower(), [], self.peers, host=config["IP"], port=config["raft"]["port"], ) self.server.start() self.client = ZeroMQClient(self.peers) @property def value(self): return self.client.leader.split(":")
def setUpClass(self): self.servers = [] for i in range(N): if i == 0: state = Leader() else: state = Follower() s = ZeroMQServer("S%d" % i, state, [], MemoryBoard(), [], 6666 + i) if (i == 0): self.leader = s self.servers.append(s) for i in range(N): me = self.servers[i] neighbors = [n for n in self.servers if n != me] me.set_neighbors(neighbors)
def __init__(self): self.peers = [] for IP, port in config["raft"]["cluster"]: srv = ZeroMQPeer("%s:%s" % (IP, port), host=IP, port=port) self.peers.append(srv) if config["raft"]["actor"]: self.server = ZeroMQServer( "%s:%s" % (config["IP"], config["raft"]["port"]), Follower(), [], self.peers, host=config["IP"], port=config["raft"]["port"], ) self.server.start() self.client = ZeroMQClient(self.peers)
import socket import datetime import time import sys import threading from server_config import CONFIG as server_config from servers.server import Server, ZeroMQServer #from states.follower import Follower from blocks.block import BlockChain from boards.memory_board import MemoryBoard import logging from states.characters import Follower if __name__ == '__main__': server_id = int(sys.argv[1]) logging.basicConfig(filename='server_' + str(server_id) + '.log', level=logging.DEBUG) observers = [ Server('localhost\t' + str(server_config[i]), Follower(), BlockChain(), MemoryBoard(), [], True) for i in server_config if i != server_id ] #for this_item in observers: # this_item._state.set_server(this_item) ZeroMQServer('localhost\t' + str(server_config[server_id]), Follower(), BlockChain(), MemoryBoard(), observers) #ZeroMQServer(this_server) while True: time.sleep(10)