Skip to content

Commit

Permalink
Router: create synchronized accessors to subDb table
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Sep 14, 2023
1 parent fe571f6 commit e24661b
Showing 1 changed file with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
* - Multihome NetDB: This is used to stash leaseSets for our own sites when they are
* sent to us by a floodfill, so that we can reply when they are requested back from us
* regardless of our closeness to them in the routing table.
* - Exploratory NetDB: This is used when we want to stash a DatabaseEntry for a key
* during exploration but don't want it to go into the Main NetDB until we do something
* else with it.
*
* And there are an unlimited number of "Client" netDbs. These sub-netDbs are
* intended to contain only the information required to operate them, and as such
Expand Down Expand Up @@ -101,10 +98,10 @@ protected FloodfillNetworkDatabaseFacade createSubNetDB(String id) {

id = clientDbidString(id);

FloodfillNetworkDatabaseFacade subdb = _subDBs.get(id);
FloodfillNetworkDatabaseFacade subdb = get(id);
if (subdb == null) {
subdb = new FloodfillNetworkDatabaseFacade(_context, id);
_subDBs.put(id, subdb);
put(id, subdb);
subdb.startup();
subdb.createHandlers();
if (subdb.getFloodfillPeers().size() == 0) {
Expand Down Expand Up @@ -148,7 +145,7 @@ public FloodfillNetworkDatabaseFacade getSubNetDB(String id) {
return mainNetDB();

id = clientDbidString(id);
return _subDBs.get(id);
return get(id);
}

/**
Expand Down Expand Up @@ -273,7 +270,7 @@ public Set<LeaseSet> getLeasesKnownToClients() {

public List<String> getClients() {
List<String> rv = new ArrayList<String>();
for (String key : _subDBs.keySet()) {
for (String key : keySet()) {
if (key != null && !key.isEmpty()) {
if (key.startsWith("client"))
rv.add(key);
Expand Down Expand Up @@ -319,7 +316,7 @@ public List<String> lookupClientBySigningPublicKey(SigningPublicKey spk) {
// to look up a client by SPK. We mostly need this for managing blinded
// and encrypted keys in the Keyring Config UI page. See also
// ConfigKeyringHelper
BlindData bd = _subDBs.get(subdb).getBlindData(spk);
BlindData bd = get(subdb).getBlindData(spk);
if (bd != null) {
rv.add(subdb);
}
Expand Down Expand Up @@ -358,7 +355,7 @@ public Set<FloodfillNetworkDatabaseFacade> getSubNetDBs() {
Set<FloodfillNetworkDatabaseFacade> rv = new HashSet<>();
rv.add(mainNetDB());
rv.add(multiHomeNetDB());
rv.addAll(_subDBs.values());
rv.addAll(values());
return rv;
}

Expand All @@ -370,4 +367,28 @@ public List<BlindData> getLocalClientsBlindData() {
}
return rv;
}

private FloodfillNetworkDatabaseFacade get(String id) {
synchronized(_subDBs) {
return _subDBs.get(id);
}
}

private void put(String id, FloodfillNetworkDatabaseFacade subdb) {
synchronized(_subDBs) {
_subDBs.put(id, subdb);
}
}

private List<String> keySet() {
synchronized(_subDBs) {
return new ArrayList<String>(_subDBs.keySet());
}
}

private List<FloodfillNetworkDatabaseFacade> values() {
synchronized(_subDBs) {
return new ArrayList<FloodfillNetworkDatabaseFacade>(_subDBs.values());
}
}
}

0 comments on commit e24661b

Please sign in to comment.