Opened 23 months ago

Last modified 22 months ago

#2382 closed enhancement

Fix isUnreachable() and wasUnreachable() in — at Version 4

Reported by: jogger Owned by: zzz
Priority: minor Milestone: 0.9.39
Component: router/transport Version: 0.9.37
Keywords: Cc:
Parent Tickets: 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()) {
                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()) {
                    return false;
                } else {
                    return true;
        RouterInfo ri = _context.netDb().lookupRouterInfoLocally(peer);
        if (ri == null)
            return false;
        return null == ri.getTargetAddress(this.getStyle());


Change History (4)

comment:1 Changed 23 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 22 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 22 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:

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

comment:4 Changed 22 months ago by zzz

Description: modified (diff)
Note: See TracTickets for help on using tickets.