Search in sources :

Example 1 with Status

use of net.i2p.router.CommSystemFacade.Status in project i2p.i2p by i2p.

the class ConnectChecker method getInboundMask.

/**
 *  Our inbound mask.
 *  For most cases, we use what we published, i.e. getConnectMask()
 *
 *  @return bitmask for accepting connections
 *  @since 0.9.34
 */
public int getInboundMask(RouterInfo us) {
    // to us
    int ct = 0;
    Status status = ctx.commSystem().getStatus();
    switch(status) {
        case OK:
        case IPV4_UNKNOWN_IPV6_OK:
        case IPV4_FIREWALLED_IPV6_OK:
        case IPV4_SNAT_IPV6_OK:
        case IPV4_SNAT_IPV6_UNKNOWN:
        case IPV4_FIREWALLED_IPV6_UNKNOWN:
        case IPV4_UNKNOWN_IPV6_FIREWALLED:
        case IPV4_OK_IPV6_FIREWALLED:
        case DIFFERENT:
        case REJECT_UNSOLICITED:
            // use what we published
            Collection<RouterAddress> at = us.getAddresses();
            if (at.isEmpty())
                return 0;
            ct = getConnectMask(at);
            break;
        case IPV4_DISABLED_IPV6_OK:
        case IPV4_DISABLED_IPV6_UNKNOWN:
        // maybe should return zero for this one?
        case IPV4_DISABLED_IPV6_FIREWALLED:
            // TODO look at force-firewalled settings per-transport
            if (!isNTCPDisabled())
                ct |= NTCP_V6;
            if (!isSSUDisabled())
                ct |= SSU_V6;
            break;
        case IPV4_OK_IPV6_UNKNOWN:
        case DISCONNECTED:
        case HOSED:
        case UNKNOWN:
        default:
            if (!isNTCPDisabled())
                ct |= NTCP_V4;
            if (!isSSUDisabled())
                ct |= SSU_V4;
            break;
    }
    return ct;
}
Also used : Status(net.i2p.router.CommSystemFacade.Status) RouterAddress(net.i2p.data.router.RouterAddress)

Example 2 with Status

use of net.i2p.router.CommSystemFacade.Status in project i2p.i2p by i2p.

the class ConnectChecker method getOutboundMask.

/**
 *  Our outbound mask.
 *  For most cases, we use our comm system status.
 *
 *  @return bitmask for initiating connections
 *  @since 0.9.34
 */
public int getOutboundMask(RouterInfo us) {
    // from us
    int cf = 0;
    Status status = ctx.commSystem().getStatus();
    switch(status) {
        case OK:
            // use what we published, as the OK state doesn't tell us about IPv6
            // Addresses.isConnectedIPv6() is too slow
            Collection<RouterAddress> a = us.getAddresses();
            if (a.isEmpty()) {
                // TODO ipv6
                if (!isNTCPDisabled())
                    cf |= NTCP_V4;
                if (!isSSUDisabled())
                    cf |= SSU_V4;
            } else {
                cf = getConnectMask(a);
            }
            break;
        case IPV4_OK_IPV6_FIREWALLED:
        case IPV4_UNKNOWN_IPV6_OK:
        case IPV4_FIREWALLED_IPV6_OK:
        case IPV4_SNAT_IPV6_OK:
        case IPV4_UNKNOWN_IPV6_FIREWALLED:
            if (!isNTCPDisabled())
                cf |= NTCP_V4 | NTCP_V6;
            if (!isSSUDisabled())
                cf |= SSU_V4 | SSU_V6;
            break;
        case IPV4_DISABLED_IPV6_OK:
        case IPV4_DISABLED_IPV6_UNKNOWN:
        case IPV4_DISABLED_IPV6_FIREWALLED:
            if (!isNTCPDisabled())
                cf |= NTCP_V6;
            if (!isSSUDisabled())
                cf |= SSU_V6;
            break;
        case DIFFERENT:
        case IPV4_SNAT_IPV6_UNKNOWN:
        case IPV4_FIREWALLED_IPV6_UNKNOWN:
        case REJECT_UNSOLICITED:
        case IPV4_OK_IPV6_UNKNOWN:
        case DISCONNECTED:
        case HOSED:
        case UNKNOWN:
        default:
            if (!isNTCPDisabled())
                cf |= NTCP_V4;
            if (!isSSUDisabled())
                cf |= SSU_V4;
            break;
    }
    return cf;
}
Also used : Status(net.i2p.router.CommSystemFacade.Status) RouterAddress(net.i2p.data.router.RouterAddress)

Example 3 with Status

use of net.i2p.router.CommSystemFacade.Status in project i2p.i2p by i2p.

the class UDPTransport method locked_addRemotePeerState.

private boolean locked_addRemotePeerState(PeerState peer) {
    Hash remotePeer = peer.getRemotePeer();
    long oldEstablishedOn = -1;
    PeerState oldPeer = null;
    if (remotePeer != null) {
        oldPeer = _peersByIdent.put(remotePeer, peer);
        if ((oldPeer != null) && (oldPeer != peer)) {
            // this happens a lot
            if (_log.shouldInfo())
                _log.info("Peer already connected (PBID): old=" + oldPeer + " new=" + peer);
            // transfer over the old state/inbound message fragments/etc
            peer.loadFrom(oldPeer);
            oldEstablishedOn = oldPeer.getKeyEstablishedTime();
        }
    }
    RemoteHostId remoteId = peer.getRemoteHostId();
    if (oldPeer != null) {
        oldPeer.dropOutbound();
        _introManager.remove(oldPeer);
        _expireEvent.remove(oldPeer);
        RemoteHostId oldID = oldPeer.getRemoteHostId();
        if (!remoteId.equals(oldID)) {
            // leak fix, remove old address
            if (_log.shouldInfo())
                _log.info(remotePeer + " changed address FROM " + oldID + " TO " + remoteId);
            PeerState oldPeer2 = _peersByRemoteHost.remove(oldID);
            // different ones in the two maps? shouldn't happen
            if (oldPeer2 != oldPeer && oldPeer2 != null) {
                oldPeer2.dropOutbound();
                _introManager.remove(oldPeer2);
                _expireEvent.remove(oldPeer2);
            }
        }
    }
    // or do we always know the IP by now?
    if (remoteId.getIP() == null && _log.shouldLog(Log.WARN))
        _log.warn("Add indirect: " + peer);
    // don't do this twice
    PeerState oldPeer2 = _peersByRemoteHost.put(remoteId, peer);
    if (oldPeer2 != null && oldPeer2 != peer && oldPeer2 != oldPeer) {
        // this shouldn't happen, should have been removed above
        if (_log.shouldLog(Log.WARN))
            _log.warn("Peer already connected (PBRH): old=" + oldPeer2 + " new=" + peer);
        // transfer over the old state/inbound message fragments/etc
        peer.loadFrom(oldPeer2);
        oldEstablishedOn = oldPeer2.getKeyEstablishedTime();
        oldPeer2.dropOutbound();
        _introManager.remove(oldPeer2);
        _expireEvent.remove(oldPeer2);
    }
    if (_log.shouldLog(Log.WARN) && !_mismatchLogged && _peersByIdent.size() != _peersByRemoteHost.size()) {
        _mismatchLogged = true;
        _log.warn("Size Mismatch after add: " + peer + " byIDsz = " + _peersByIdent.size() + " byHostsz = " + _peersByRemoteHost.size());
    }
    _activeThrottle.unchoke(peer.getRemotePeer());
    markReachable(peer.getRemotePeer(), peer.isInbound());
    // _context.banlist().unbanlistRouter(peer.getRemotePeer(), STYLE);
    // if (SHOULD_FLOOD_PEERS)
    // _flooder.addPeer(peer);
    _expireEvent.add(peer);
    _introManager.add(peer);
    if (oldEstablishedOn > 0)
        _context.statManager().addRateData("udp.alreadyConnected", oldEstablishedOn);
    synchronized (_rebuildLock) {
        rebuildIfNecessary();
        Status status = getReachabilityStatus();
        if (status != Status.OK && status != Status.IPV4_OK_IPV6_UNKNOWN && status != Status.IPV4_OK_IPV6_FIREWALLED && status != Status.IPV4_DISABLED_IPV6_OK && status != Status.IPV4_DISABLED_IPV6_UNKNOWN && status != Status.IPV4_DISABLED_IPV6_FIREWALLED && status != Status.DISCONNECTED && _reachabilityStatusUnchanged < 7) {
            _testEvent.forceRunSoon(peer.isIPv6());
        }
    }
    return true;
}
Also used : Status(net.i2p.router.CommSystemFacade.Status) Hash(net.i2p.data.Hash)

Example 4 with Status

use of net.i2p.router.CommSystemFacade.Status in project i2p.i2p by i2p.

the class UDPTransport method getIsPortFixed.

/**
 *  Was true before 0.9.2
 *  Now false if we need introducers (as perhaps that's why we need them,
 *  our firewall is changing our port), unless overridden by the property.
 *  We must have an accurate external port when firewalled, or else
 *  our signature of the SessionCreated packet will be invalid.
 */
private boolean getIsPortFixed() {
    String prop = _context.getProperty(PROP_FIXED_PORT);
    if (prop != null)
        return Boolean.parseBoolean(prop);
    Status status = getReachabilityStatus();
    return status != Status.REJECT_UNSOLICITED && status != Status.IPV4_FIREWALLED_IPV6_OK && status != Status.IPV4_FIREWALLED_IPV6_UNKNOWN;
}
Also used : Status(net.i2p.router.CommSystemFacade.Status)

Example 5 with Status

use of net.i2p.router.CommSystemFacade.Status in project i2p.i2p by i2p.

the class UDPTransport method locked_setReachabilityStatus.

/**
 *  @param isIPv6 Is the change an IPv6 change?
 */
private void locked_setReachabilityStatus(Status newStatus, boolean isIPv6) {
    Status old = _reachabilityStatus;
    // merge new status into old
    Status status = Status.merge(old, newStatus);
    _testEvent.setLastTested(isIPv6);
    // now modify if we are IPv6 only
    TransportUtil.IPv6Config config = getIPv6Config();
    if (config == IPV6_ONLY) {
        if (status == Status.IPV4_UNKNOWN_IPV6_OK)
            status = Status.IPV4_DISABLED_IPV6_OK;
        else if (status == Status.IPV4_UNKNOWN_IPV6_FIREWALLED)
            status = Status.IPV4_DISABLED_IPV6_FIREWALLED;
        else if (status == Status.UNKNOWN)
            status = Status.IPV4_DISABLED_IPV6_UNKNOWN;
    }
    if (status != Status.UNKNOWN) {
        // now modify if we have no IPv6 address
        if (_currentOurV6Address == null && !_haveIPv6Address) {
            if (status == Status.IPV4_OK_IPV6_UNKNOWN)
                status = Status.OK;
            else if (status == Status.IPV4_FIREWALLED_IPV6_UNKNOWN)
                status = Status.REJECT_UNSOLICITED;
            else if (status == Status.IPV4_SNAT_IPV6_UNKNOWN)
                status = Status.DIFFERENT;
            else // prevent firewalled -> OK -> firewalled+OK
            if (status == Status.IPV4_FIREWALLED_IPV6_OK)
                status = Status.REJECT_UNSOLICITED;
            else if (status == Status.IPV4_SNAT_IPV6_OK)
                status = Status.DIFFERENT;
        }
        if (status != old) {
            // to prevent thrashing
            if ((old == Status.OK && (status == Status.DIFFERENT || status == Status.REJECT_UNSOLICITED || status == Status.IPV4_FIREWALLED_IPV6_OK || status == Status.IPV4_SNAT_IPV6_OK || status == Status.IPV4_OK_IPV6_FIREWALLED)) || (status == Status.OK && (old == Status.DIFFERENT || old == Status.REJECT_UNSOLICITED || old == Status.IPV4_FIREWALLED_IPV6_OK || old == Status.IPV4_SNAT_IPV6_OK || old == Status.IPV4_OK_IPV6_FIREWALLED))) {
                if (status != _reachabilityStatusPending) {
                    if (_log.shouldLog(Log.WARN))
                        _log.warn("Old status: " + old + " status pending confirmation: " + status + " Caused by update: " + newStatus);
                    _reachabilityStatusPending = status;
                    _testEvent.forceRunSoon(isIPv6);
                    return;
                }
            }
            _reachabilityStatusUnchanged = 0;
            long now = _context.clock().now();
            _reachabilityStatusLastUpdated = now;
            _reachabilityStatus = status;
        } else {
            _reachabilityStatusUnchanged++;
        }
        _reachabilityStatusPending = status;
    }
    if (status != old) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("Old status: " + old + " New status: " + status + " Caused by update: " + newStatus + " from: ", new Exception("traceback"));
        if (old != Status.UNKNOWN)
            _context.router().eventLog().addEvent(EventLog.REACHABILITY, "from " + _t(old.toStatusString()) + " to " + _t(status.toStatusString()));
        // Always rebuild when the status changes, even if our address hasn't changed,
        // as rebuildExternalAddress() calls replaceAddress() which calls CSFI.notifyReplaceAddress()
        // which will start up NTCP inbound when we transition to OK.
        // if (needsRebuild())
        rebuildExternalAddress();
    } else {
        if (_log.shouldLog(Log.INFO))
            _log.info("Status unchanged: " + _reachabilityStatus + " after update: " + newStatus + " (unchanged " + _reachabilityStatusUnchanged + " consecutive times), last updated " + DataHelper.formatDuration(_context.clock().now() - _reachabilityStatusLastUpdated) + " ago");
    }
}
Also used : Status(net.i2p.router.CommSystemFacade.Status) IPv6Config(net.i2p.router.transport.TransportUtil.IPv6Config) TransportUtil(net.i2p.router.transport.TransportUtil) SocketException(java.net.SocketException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

Status (net.i2p.router.CommSystemFacade.Status)8 RouterAddress (net.i2p.data.router.RouterAddress)3 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 Hash (net.i2p.data.Hash)1 RouterInfo (net.i2p.data.router.RouterInfo)1 FloodfillNetworkDatabaseFacade (net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade)1 TransportUtil (net.i2p.router.transport.TransportUtil)1 IPv6Config (net.i2p.router.transport.TransportUtil.IPv6Config)1