Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Public Member Functions | Public Attributes | List of all members
coordinator.server.Server Class Reference

Public Member Functions

def __init__ (self, IContributionHandler handler, Configuration server_config, str server_dir)
 
None stop (self)
 

Public Attributes

 handler
 
 config
 
 upload_file
 
 state_file_path
 
 processing
 
 contributors
 
 state
 
 handler_finalized
 
 state_lock
 
 thread
 
 server
 

Detailed Description

Server to coordinate an MPC, that serves challenges and accepts responses
from contributors. Performs basic contribution management, ensuring
contributions are from the correct party and submitted within the correct
time window. MPC-specific operations (validation / challenge computation,
etc) are performed by an IContributionHandler object.

Definition at line 38 of file server.py.

Constructor & Destructor Documentation

◆ __init__()

def coordinator.server.Server.__init__ (   self,
IContributionHandler  handler,
Configuration  server_config,
str  server_dir 
)

Definition at line 47 of file server.py.

47  def __init__(
48  self,
49  handler: IContributionHandler,
50  server_config: Configuration,
51  server_dir: str):
52 
53  logging.basicConfig(filename=LOG_FILE, level=logging.DEBUG)
54  self.handler = handler
55  self.config = server_config
56  self.contributors: ContributorList
57  self.upload_file = join(server_dir, UPLOAD_FILE)
58  self.state_file_path = join(server_dir, STATE_FILE)
59  self.state: ServerState
60  self.processing = False
61 
62  # Try to open contributors file and state files. Perform sanity checks.
63  with open(self.config.contributors_file, "r") as contributors_f:
64  self.contributors = ContributorList.from_json(contributors_f.read())
65  print(f"Contributors: {self.contributors}")
66  self.contributors.ensure_validity()
67 
68  if exists(STATE_FILE):
69  info(f"run_server: using existing state file: {STATE_FILE}")
70  with open(STATE_FILE, "r") as state_f:
71  self.state = ServerState.from_json(state_f.read())
72  else:
73  self.state = initial_server_state(self.config, self.contributors)
74  self._write_state_file()
75  self._notify_next_contributor()
76 
77  self.handler_finalized = self.state.have_all_contributions()
78  self.state_lock = Lock()
79  self.server: Optional[WSGIServer] = None
80  self.thread = Thread(target=self._run)
81  self.thread.start()
82 
83  while self.server is None or self.server.socket is None:
84  info("Waiting for MPC server to start ...")
85  time.sleep(1)
86  port = self.server.socket.getsockname()[1]
87  info(f"MPC server started (port: {port}).")
88 

Member Function Documentation

◆ stop()

None coordinator.server.Server.stop (   self)

Definition at line 89 of file server.py.

89  def stop(self) -> None:
90  if self.server is not None:
91  self.server.stop()
92  while self.server is not None:
93  info("Waiting for server to stop ...")
94  time.sleep(1.0)
95  self.thread.join()
96  info("Server stopped.")
97 
Here is the call graph for this function:

Member Data Documentation

◆ config

coordinator.server.Server.config

Definition at line 51 of file server.py.

◆ contributors

coordinator.server.Server.contributors

Definition at line 60 of file server.py.

◆ handler

coordinator.server.Server.handler

Definition at line 50 of file server.py.

◆ handler_finalized

coordinator.server.Server.handler_finalized

Definition at line 73 of file server.py.

◆ processing

coordinator.server.Server.processing

Definition at line 56 of file server.py.

◆ server

coordinator.server.Server.server

Definition at line 336 of file server.py.

◆ state

coordinator.server.Server.state

Definition at line 67 of file server.py.

◆ state_file_path

coordinator.server.Server.state_file_path

Definition at line 54 of file server.py.

◆ state_lock

coordinator.server.Server.state_lock

Definition at line 74 of file server.py.

◆ thread

coordinator.server.Server.thread

Definition at line 76 of file server.py.

◆ upload_file

coordinator.server.Server.upload_file

Definition at line 53 of file server.py.


The documentation for this class was generated from the following file:
coordinator.server_state.initial_server_state
ServerState initial_server_state(Configuration configuration, ContributorList contributors)
Definition: server_state.py:86