Opened 10 months ago

Closed 9 months ago

Last modified 9 months ago

#2382 closed enhancement (fixed)

Fix isUnreachable() and wasUnreachable() in TransportImpl.java

Reported by: jogger Owned by: zzz
Priority: minor Milestone: 0.9.39
Component: router/transport Version: 0.9.37
Keywords: Cc:
Parent Tickets: #2355 Sensitive: no

Description (last modified by zzz)

The following code takes the now() out of the critical path. Part of the solution for 2355.

    public boolean isUnreachable(Hash peer) {
 //       long now = _context.clock().now();
        synchronized (_unreachableEntries) {
            Long when = _unreachableEntries.get(peer);
            if (when == null) return false;
//            if (when.longValue() + UNREACHABLE_PERIOD < now) {
            if (when.longValue() + UNREACHABLE_PERIOD < _context.clock().now()) {
                _unreachableEntries.remove(peer);
                return false;
            } else {
                return true;
            }
        }
    }

    public boolean wasUnreachable(Hash peer) {
//        long now = _context.clock().now();
        synchronized (_wasUnreachableEntries) {
            Long when = _wasUnreachableEntries.get(peer);
            if (when != null) {
//                if (when.longValue() + WAS_UNREACHABLE_PERIOD < now) {
                if (when.longValue() + WAS_UNREACHABLE_PERIOD < _context.clock().now()) {
                    _unreachableEntries.remove(peer);
                    return false;
                } else {
                    return true;
                }
            }
        }
        RouterInfo ri = _context.netDb().lookupRouterInfoLocally(peer);
        if (ri == null)
            return false;
        return null == ri.getTargetAddress(this.getStyle());
    }

Subtickets

Change History (6)

comment:1 Changed 10 months ago by Zlatin Balevsky

I get the idea but it's a bit difficult to read. Can you format it as a diff?

comment:2 Changed 10 months ago by jogger

never worked with diff.

now() may not be needed at all. So one can ditch the now variable and move _context.clock().now() right to the point.

The "else" is also unnecessary.

comment:3 Changed 10 months ago by zzz

you asked us over on zzz.i2p how you could contribute more; providing diffs would be a big help.

assuming you're on linux or similar:

cp Foo.java Foo.java.orig
(make your changes to Foo.java)
diff -u Foo.java.orig Foo.java > foo.diff
(attach foo.diff here, or copy it between three open curly braces and three close curly braces)

comment:4 Changed 10 months ago by zzz

Description: modified (diff)

comment:5 Changed 9 months ago by zzz

Milestone: undecided0.9.39
Priority: majorminor
Resolution: fixed
Status: newclosed

comment:6 Changed 9 months ago by zzz

Parent Tickets: 2355
Note: See TracTickets for help on using tickets.