Skip to content

Commit

Permalink
added index for client_id & made sure client_id is used for /add_clie…
Browse files Browse the repository at this point in the history
…nt as well
  • Loading branch information
niklastheman committed Jun 25, 2024
1 parent fa5c739 commit 55a2231
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def add_combiner(self, combiner_id, secure_grpc, address, remote_addr, fqdn, por

return jsonify(payload)

def add_client(self, client_id, preferred_combiner, remote_addr):
def add_client(self, client_id, preferred_combiner, remote_addr, name):
"""Add a client to the network.
:param client_id: The client id to add.
Expand Down Expand Up @@ -600,7 +600,8 @@ def add_client(self, client_id, preferred_combiner, remote_addr):
)

client_config = {
"name": client_id,
"client_id": client_id,
"name": name,
"combiner_preferred": preferred_combiner,
"combiner": combiner.name,
"ip": remote_addr,
Expand Down
4 changes: 2 additions & 2 deletions fedn/network/api/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ def add_client(self, client):
:type client: dict
:return: None
"""
if self.get_client(client["name"]):
if self.get_client(client["client_id"]):
return

logger.info("adding client {}".format(client["name"]))
logger.info("adding client {}".format(client["client_id"]))
self.statestore.set_client(client)

def get_client(self, name):
Expand Down
2 changes: 1 addition & 1 deletion fedn/network/clients/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def assign(self):
"""
try:
retval = None
payload = {"client_id": self.name, "preferred_combiner": self.preferred_combiner}
payload = {"name": self.name, "client_id": self.id, "preferred_combiner": self.preferred_combiner}
retval = requests.post(
self.connect_string + FEDN_CUSTOM_URL_PREFIX + "/add_client",
json=payload,
Expand Down
13 changes: 7 additions & 6 deletions fedn/network/storage/statestore/mongostatestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def connect(self):

def init_index(self):
self.package.create_index([("id", pymongo.DESCENDING)])
self.clients.create_index([("client_id", pymongo.DESCENDING)])

def is_inited(self):
"""Check if the statestore is intialized.
Expand Down Expand Up @@ -726,18 +727,18 @@ def set_client(self, client_data):
:return:
"""
client_data["updated_at"] = str(datetime.now())
self.clients.update_one({"name": client_data["name"]}, {"$set": client_data}, True)
self.clients.update_one({"client_id": client_data["client_id"]}, {"$set": client_data}, True)

def get_client(self, name):
"""Get client by name.
def get_client(self, client_id):
"""Get client by client_id.
:param name: name of client to get.
:type name: str
:param client_id: client_id of client to get.
:type client_id: str
:return: The client. None if not found.
:rtype: ObjectId
"""
try:
ret = self.clients.find({"key": name})
ret = self.clients.find({"key": client_id})
if list(ret) == []:
return None
else:
Expand Down

0 comments on commit 55a2231

Please sign in to comment.