Skip to content

Commit

Permalink
Removing pathWeight from all of Emissary (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
sambish5 authored Sep 5, 2023
1 parent aacc0fc commit 2d36dd7
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 79 deletions.
12 changes: 0 additions & 12 deletions src/main/java/emissary/client/response/Directory.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public class Directory implements Comparable<Directory>, Serializable {
@XmlElement(name = "expense")
private int expense;

@XmlElement(name = "pathWeight")
private int pathWeight;

public Directory() {}

public Directory(DirectoryEntry directoryEntry) {
Expand All @@ -48,7 +45,6 @@ private void setUpEntryInfo() {
cost = directoryEntry.getCost();
quality = directoryEntry.getQuality();
expense = directoryEntry.getExpense();
pathWeight = directoryEntry.getPathWeight();
}

public DirectoryEntry getDirectoryEntry() {
Expand Down Expand Up @@ -99,14 +95,6 @@ public void setExpense(int expense) {
this.expense = expense;
}

public int getPathWeight() {
return pathWeight;
}

public void setPathWeight(int pathWeight) {
this.pathWeight = pathWeight;
}

@Override
public int compareTo(Directory o) {
return getEntry().compareTo(o.getEntry());
Expand Down
47 changes: 0 additions & 47 deletions src/main/java/emissary/directory/DirectoryEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ public class DirectoryEntry implements Serializable {
*/
protected int theExpense = 0;

/**
* Nominal starting path weight. Making it lower makes the entry less likely to be selected from a group with equal
* expense. Making it higher makes it more likely to be selected from a group with equal expense. Between entries with
* different expense values there is no effect.
*/
protected transient int pathWeight = 500;

/** Protection against repeated namespace lookups for this entry */
protected transient boolean lookupAttempted = false;

Expand Down Expand Up @@ -215,7 +208,6 @@ public DirectoryEntry(final DirectoryEntry that) {
this.theQuality = that.theQuality;
this.theCost = that.theCost;
this.calculateExpense();
this.pathWeight = that.pathWeight;
this.description = that.description;
if (preserveTime) {
this.age = that.age;
Expand Down Expand Up @@ -332,45 +324,6 @@ protected void setKey(final String key) {
}
}

/**
* Get the path weight of moving to a place Nominal starting path weight is 500. Making it lower makes the entry less
* likely to be selected from a group with equal expense. Making it higher makes it more likely to be selected from a
* group with equal expense. Between entries with different expense values there is no effect. The value is not allowed
* to go below zero.
*
* @return the current path weight value
*/
public int getPathWeight() {
return this.pathWeight;
}

/**
* Set the path weight of moving to a place
*
* @see #getPathWeight()
*/
public void setPathWeight(final int value) {
this.pathWeight = value;
if (this.pathWeight < 0) {
this.pathWeight = 0;
}
}


/**
* Add to the path weight. The increment can be negative to remove weight. The path weight is not allowed to go below
* zero.
*
* @see #getPathWeight()
* @param weightIncrement amount to add to weight
*/
public void addPathWeight(final int weightIncrement) {
this.pathWeight += weightIncrement;
if (this.pathWeight < 0) {
this.pathWeight = 0;
}
}

/**
* Set a new data type
*
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/emissary/directory/DirectoryPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -820,13 +820,10 @@ public int irdFailDirectory(final String key, final boolean permanent) {
logger.debug("Permanent failure of remote {}", key);
count += removePlaces(Collections.singletonList(hmKey));
} else {
// Change the weight of the paths for all places matching the
// Change the cost for all places matching the
// failed directory. This has the effect of causing them
// not to be chosen as much.
final List<DirectoryEntry> list = this.entryMap.collectAllMatching(hmKey);
for (final DirectoryEntry e : list) {
e.addPathWeight(-20);
}
this.observerManager.placeCostChangeEntries(list);
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/emissary/server/mvc/DumpDirectoryAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public class DirectoryEntryInfo {
final int cost;
final int quality;
final int expense;
final int pathWeight;
final String age;

public DirectoryEntryInfo(String stripe, DirectoryEntry entry, long now) {
Expand All @@ -152,7 +151,6 @@ public DirectoryEntryInfo(String stripe, DirectoryEntry entry, long now) {
this.cost = entry.getCost();
this.quality = entry.getQuality();
this.expense = entry.getExpense();
this.pathWeight = entry.getPathWeight();
long ago = now - entry.getAge();
long hh = ago / 3600000;
long mm = (ago % 3600000) / 60000;
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/templates/dump_directory.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<th>Cost</th>
<th>Quality</th>
<th title="Computed from Cost and quality">Expense</th>
<th title="Path Weight">PW</th>
<th title="HH:MM:SS">Age</th>
</tr>
</thead>
Expand All @@ -33,7 +32,6 @@
<td class="num">{{cost}}</td>
<td class="num">{{quality}}</td>
<td class="num">{{expense}}</td>
<td class="num">{{pathWeight}}</td>
<td class="num">{{age}}</td>
</tr>
{{/entrylist}}
Expand Down
11 changes: 0 additions & 11 deletions src/test/java/emissary/directory/DirectoryEntryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,6 @@ void testAdd() {
final int newExp = DirectoryEntry.calculateExpense(cost + 100, quality);
assertEquals(newExp, this.d.getExpense(), "Expense computation on cost increment");
assertTrue(this.d.toString().contains("$" + newExp), "Correct expense in key");

final int origWeight = this.d.getPathWeight();
this.d.addPathWeight(100);
assertEquals(100 + origWeight, this.d.getPathWeight(), "Path weight incrememented");

this.d.addPathWeight(-100000);
assertEquals(0, this.d.getPathWeight(), "Path weight cannot be negative");

this.d.setPathWeight(-1);
assertEquals(0, this.d.getPathWeight(), "Path weight cannot be negative");
}

@Test
Expand Down Expand Up @@ -156,7 +146,6 @@ void testCopyConstructor() {
assertEquals(this.d.getDescription(), copy.getDescription(), "Copied desc");
assertEquals(this.d.toString(), copy.toString(), "Copied tostring");
assertEquals(this.d.getFullKey(), copy.getFullKey(), "Full key");
assertEquals(this.d.getPathWeight(), copy.getPathWeight(), "Copied path weight");
}

@Test
Expand Down
1 change: 0 additions & 1 deletion src/test/java/emissary/server/api/EmissaryApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ void directories() throws IOException {
foundCost.add(entry.getCost());
assertEquals(50, entry.getQuality(), "Quality is expected to be 50 for all entries.");
foundExpense.add(entry.getExpense());
assertEquals(500, entry.getPathWeight(), "PathWeight is expected to be 500 for all entries.");
});
assertEquals(expEntryKeys, foundEntryKeys);
assertEquals(expDataIds, foundDataIds);
Expand Down

0 comments on commit 2d36dd7

Please sign in to comment.