Skip to content

Commit

Permalink
Fix remainder of missing reversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
PsiLupan committed Jun 20, 2018
1 parent 9b57178 commit 317714a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/mlga/ui/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import mlga.Boot;
import mlga.io.FileUtil;
import mlga.io.Settings;
import mlga.io.peer.PeerTracker;

public class Overlay extends JPanel {
private static final long serialVersionUID = -470849574354121503L;
Expand All @@ -36,9 +37,13 @@ public class Overlay extends JPanel {
/** idx & fh are updated by listener and rendering events. <br>They track hovered index and font height. */
private int idx = -1, fh = 0;

private final PeerTracker peerTracker;

private final JWindow frame;

public Overlay() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException, FontFormatException, IOException {
peerTracker = new PeerTracker();
peerTracker.start();

InputStream is = FileUtil.localResource("Roboto-Medium.ttf");
roboto = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(15f);
Expand Down Expand Up @@ -144,7 +149,7 @@ public void run() {
}

private void addPeer(Inet4Address addr, long rtt) {
peers.add(new Peer(addr, rtt));
peers.add(new Peer(addr, rtt, peerTracker.getPeer(addr)));
}

/** Sets a peer's ping, or creates their object. */
Expand Down
40 changes: 38 additions & 2 deletions src/mlga/ui/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@

import java.net.Inet4Address;

import mlga.io.peer.IOPeer;
import mlga.io.peer.IOPeer.Status;

/** Simple wrapper to visually represent a Peer that is connected. */
public class Peer {
private Inet4Address id;
private long ping = 0;
private boolean blocked;
private boolean hasStatus = false;
private long last_seen;

public Peer(Inet4Address hash, long ttl) {
private IOPeer io;

public Peer(Inet4Address hash, long rtt, IOPeer io) {
this.io = io;
this.id = hash;
this.ping = rtt;
this.hasStatus = io.getStatus() != Status.UNRATED;
if (this.hasStatus) {
this.blocked = io.getStatus() == Status.BLOCKED;
}
this.last_seen = System.currentTimeMillis();
}

Expand All @@ -27,8 +40,31 @@ public long getPing() {
return this.ping;
}

/** If we have saved, and also blocked, this Peer. */
public boolean blocked() {
return this.hasStatus && this.blocked;
}

/** Save our opinion of this Peer. */
public void rate(boolean block) {
this.hasStatus = true;
this.blocked = block;
this.io.setStatus(block ? Status.BLOCKED : Status.LOVED);
}

/** Remove this peer from the Preferences. */
public void unsave() {
this.hasStatus = false;
this.io.setStatus(Status.UNRATED);
}

/** If we've saved this Peer before. */
public boolean saved() {
return this.hasStatus;
}

/** Returns the time (in milliseconds) since this Peer was last pinged. */
public long age() {
return System.currentTimeMillis() - this.last_seen;
}
}
}

0 comments on commit 317714a

Please sign in to comment.