Skip to content

Commit

Permalink
Router: add removal functions to FNDS/SNDF
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Sep 14, 2023
1 parent e24661b commit 6e636c5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public FloodfillNetworkDatabaseFacade getSubNetDB(Hash dbid){
return null;
}

public void removeSubNetDB(String dbid) {
return;
}

public void removeSubNetDB(Hash dbid) {
return;
}

public void restart() {}
public void shutdown() {}
public void startup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ protected FloodfillNetworkDatabaseFacade createSubNetDB(String id) {
if (id.equals(myHash.toBase32()))
return mainNetDB();


id = clientDbidString(id);

FloodfillNetworkDatabaseFacade subdb = get(id);
Expand All @@ -116,14 +115,6 @@ protected FloodfillNetworkDatabaseFacade createSubNetDB(String id) {
return subdb;
}

private String clientDbidString(String id) {
if (id.endsWith(".i2p")) {
if (!id.startsWith("clients_"))
id = "clients_" + id;
}
return id;
}

@Override
public FloodfillNetworkDatabaseFacade getSubNetDB(Hash dbid) {
if (dbid == null)
Expand All @@ -148,6 +139,35 @@ public FloodfillNetworkDatabaseFacade getSubNetDB(String id) {
return get(id);
}

@Override
public void removeSubNetDB(Hash id) {
if (id == null)
return;
Hash myHash = _context.routerHash();
if (id.equals(myHash.toBase32()))
return;

String dbid = id.toBase32();
dbid = clientDbidString(dbid);
remove(dbid);
}

@Override
public void removeSubNetDB(String id) {
if (id == null || id.isEmpty() || id.equals(MAIN_DBID))
return;
if (id.equals(MULTIHOME_DBID))
return;
if (id.equals(EXPLORATORY_DBID))
return;
Hash myHash = _context.routerHash();
if (id.equals(myHash.toBase32()))
return;

String dbid = clientDbidString(id);
remove(dbid);
}

/**
* If we are floodfill, turn it off and tell everybody.
*
Expand Down Expand Up @@ -380,6 +400,12 @@ private void put(String id, FloodfillNetworkDatabaseFacade subdb) {
}
}

private void remove(String id) {
synchronized(_subDBs) {
_subDBs.remove(id);
}
}

private List<String> keySet() {
synchronized(_subDBs) {
return new ArrayList<String>(_subDBs.keySet());
Expand All @@ -391,4 +417,12 @@ private List<FloodfillNetworkDatabaseFacade> values() {
return new ArrayList<FloodfillNetworkDatabaseFacade>(_subDBs.values());
}
}

private String clientDbidString(String id) {
if (id.endsWith(".i2p")) {
if (!id.startsWith("clients_"))
id = "clients_" + id;
}
return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public SegmentedNetworkDatabaseFacade(RouterContext context) {
public abstract FloodfillNetworkDatabaseFacade createSubNetDB(Hash dbid);
public abstract FloodfillNetworkDatabaseFacade getSubNetDB(String dbid);
public abstract FloodfillNetworkDatabaseFacade getSubNetDB(Hash dbid);
public abstract void removeSubNetDB(String dbid);
public abstract void removeSubNetDB(Hash dbid);
public abstract FloodfillNetworkDatabaseFacade mainNetDB();
public abstract FloodfillNetworkDatabaseFacade multiHomeNetDB();
public abstract FloodfillNetworkDatabaseFacade clientNetDB(String dbid);
Expand Down

0 comments on commit 6e636c5

Please sign in to comment.