Changeset c76c800


Ignore:
Timestamp:
May 9, 2013 5:32:29 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
5e953b0
Parents:
3a49d6d
Message:
  • NTCP:
    • Drop NTCPAddress, just use RouterAddress?
    • Drop _myAddress field, use super's currentAddress
Location:
router/java/src/net/i2p/router/transport
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/transport/ntcp/EventPumper.java

    r3a49d6d rc76c800  
    2121
    2222import net.i2p.I2PAppContext;
     23import net.i2p.data.RouterAddress;
    2324import net.i2p.data.RouterIdentity;
    2425import net.i2p.router.CommSystemFacade;
     
    779780                con.setKey(key);
    780781                try {
    781                     NTCPAddress naddr = con.getRemoteAddress();
    782                             if (naddr.getPort() <= 0)
    783                                 throw new IOException("Invalid NTCP address: " + naddr);
     782                    RouterAddress naddr = con.getRemoteAddress();
     783                    if (naddr.getPort() <= 0)
     784                        throw new IOException("Invalid NTCP address: " + naddr);
    784785                    InetSocketAddress saddr = new InetSocketAddress(naddr.getHost(), naddr.getPort());
    785786                    boolean connected = con.getChannel().connect(saddr);
  • router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java

    r3a49d6d rc76c800  
    1717import net.i2p.data.ByteArray;
    1818import net.i2p.data.DataHelper;
     19import net.i2p.data.RouterAddress;
    1920import net.i2p.data.RouterIdentity;
    2021import net.i2p.data.RouterInfo;
     
    8788    private final boolean _isInbound;
    8889    private volatile boolean _closed;
    89     private NTCPAddress _remAddr;
     90    private RouterAddress _remAddr;
    9091    private RouterIdentity _remotePeer;
    9192    private long _clockSkew; // in seconds
     
    183184     *
    184185     */
    185     public NTCPConnection(RouterContext ctx, NTCPTransport transport, RouterIdentity remotePeer, NTCPAddress remAddr) {
     186    public NTCPConnection(RouterContext ctx, NTCPTransport transport, RouterIdentity remotePeer, RouterAddress remAddr) {
    186187        _context = ctx;
    187188        _log = ctx.logManager().getLog(getClass());
     
    220221    public boolean isEstablished() { return _established; }
    221222    public EstablishState getEstablishState() { return _establishState; }
    222     public NTCPAddress getRemoteAddress() { return _remAddr; }
     223    public RouterAddress getRemoteAddress() { return _remAddr; }
    223224    public RouterIdentity getRemotePeer() { return _remotePeer; }
    224225    public void setRemotePeer(RouterIdentity ident) { _remotePeer = ident; }
  • router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java

    r3a49d6d rc76c800  
    5656    private final Object _conLock;
    5757    private final Map<Hash, NTCPConnection> _conByIdent;
    58     private NTCPAddress _myAddress;
    5958    private final EventPumper _pumper;
    6059    private final Reader _reader;
     
    7069    public final static String PROP_I2NP_NTCP_AUTO_PORT = "i2np.ntcp.autoport";
    7170    public final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip";
     71    public static final int DEFAULT_COST = 10;
    7272   
    7373    /** this is rarely if ever used, default is to bind to wildcard address */
     
    204204                    RouterAddress addr = getTargetAddress(target);
    205205                    if (addr != null) {
    206                         NTCPAddress naddr = new NTCPAddress(addr);
    207                         con = new NTCPConnection(_context, this, ident, naddr);
     206                        con = new NTCPConnection(_context, this, ident, addr);
    208207                        if (_log.shouldLog(Log.DEBUG))
    209                             _log.debug("Send on a new con: " + con + " at " + addr + " for " + ih.toBase64());
     208                            _log.debug("Send on a new con: " + con + " at " + addr + " for " + ih);
    210209                        _conByIdent.put(ih, con);
    211210                    } else {
     
    327326            _log.debug("slow bid when trying to send to " + peer);
    328327        if (haveCapacity()) {
    329             if (addr.getCost() > NTCPAddress.DEFAULT_COST)
     328            if (addr.getCost() > DEFAULT_COST)
    330329                return _slowCostBid;
    331330            else
    332331                return _slowBid;
    333332        } else {
    334             if (addr.getCost() > NTCPAddress.DEFAULT_COST)
     333            if (addr.getCost() > DEFAULT_COST)
    335334                return _nearCapacityCostBid;
    336335            else
     
    475474
    476475        startIt();
    477         configureLocalAddress();
    478         bindAddress();
     476        RouterAddress addr = configureLocalAddress();
     477        if (addr != null)
     478        bindAddress(addr);
    479479    }
    480480
     
    483483     *  Caller should stop the transport first, then
    484484     *  verify stopped with isAlive()
     485     *
     486     *  @param addr may be null
    485487     */
    486488    private synchronized void restartListening(RouterAddress addr) {
     
    492494
    493495        startIt();
    494         if (addr == null)
    495             _myAddress = null;
    496         else
    497             _myAddress = new NTCPAddress(addr);
    498         bindAddress();
     496        if (addr != null)
     497            bindAddress(addr);
    499498    }
    500499
     
    527526    }
    528527
    529     /** call from synchronized method */
    530     private RouterAddress bindAddress() {
    531         if (_myAddress != null) {
     528    /**
     529     *  call from synchronized method
     530     *  @param myAddress new address, may be null
     531     *  @return new address or null
     532     */
     533    private RouterAddress bindAddress(RouterAddress myAddress) {
     534        if (myAddress != null) {
    532535            InetAddress bindToAddr = null;
    533536            String bindTo = _context.getProperty(PROP_BIND_INTERFACE);
     
    565568                chan.configureBlocking(false);
    566569
    567                 int port = _myAddress.getPort();
     570                int port = myAddress.getPort();
    568571                if (port > 0 && port < 1024)
    569572                    _log.logAlways(Log.WARN, "Specified NTCP port is " + port + ", ports lower than 1024 not recommended");
     
    588591        }
    589592
    590         if (_myAddress != null) {
    591             RouterAddress rv = _myAddress.toRouterAddress();
    592             if (rv != null)
    593                 replaceAddress(rv);
    594             return rv;
     593        if (myAddress != null) {
     594            replaceAddress(myAddress);
     595            return myAddress;
    595596        } else {
    596597            return null;
     
    645646    //private boolean bindAllInterfaces() { return true; }
    646647
    647     /** caller must synch on this */
    648     private void configureLocalAddress() {
     648    /**
     649     *  Generally returns null
     650     *  caller must synch on this
     651     */
     652    private RouterAddress configureLocalAddress() {
    649653            // this generally returns null -- see javadoc
    650             RouterAddress ra = createNTCPAddress();
    651             if (ra != null) {
    652                 NTCPAddress addr = new NTCPAddress(ra);
     654            RouterAddress addr = createNTCPAddress();
     655            if (addr != null) {
    653656                if (addr.getPort() <= 0) {
    654                     _myAddress = null;
     657                    addr = null;
    655658                    if (_log.shouldLog(Log.ERROR))
    656659                        _log.error("NTCP address is outbound only, since the NTCP configuration is invalid");
    657660                } else {
    658                     _myAddress = addr;
    659                     replaceAddress(ra);
    660661                    if (_log.shouldLog(Log.INFO))
    661                         _log.info("NTCP address configured: " + _myAddress);
     662                        _log.info("NTCP address configured: " + addr);
    662663                }
    663664            } else {
     
    665666                    _log.info("NTCP address is outbound only");
    666667            }
     668            return addr;
    667669    }
    668670
     
    683685            return null;
    684686        OrderedProperties props = new OrderedProperties();
    685         props.setProperty(NTCPAddress.PROP_HOST, name);
    686         props.setProperty(NTCPAddress.PROP_PORT, Integer.toString(p));
    687         RouterAddress addr = new RouterAddress(STYLE, props, NTCPAddress.DEFAULT_COST);
     687        props.setProperty(RouterAddress.PROP_HOST, name);
     688        props.setProperty(RouterAddress.PROP_PORT, Integer.toString(p));
     689        RouterAddress addr = new RouterAddress(STYLE, props, DEFAULT_COST);
    688690        return addr;
    689691    }
     
    721723        int cost;
    722724        if (oldAddr == null) {
    723             cost = NTCPAddress.DEFAULT_COST;
     725            cost = DEFAULT_COST;
    724726        } else {
    725727            cost = oldAddr.getCost();
     
    734736        // new behavior (>= 0.7.4): auto-port defaults to true, but explicit setting trumps auto
    735737        // TODO rewrite this to operate on ints instead of strings
    736         String oport = newProps.getProperty(NTCPAddress.PROP_PORT);
     738        String oport = newProps.getProperty(RouterAddress.PROP_PORT);
    737739        String nport = null;
    738740        String cport = _context.getProperty(PROP_I2NP_NTCP_PORT);
     
    758760        //if (oport == null || ! oport.equals(nport)) {
    759761        if (oport == null) {
    760             newProps.setProperty(NTCPAddress.PROP_PORT, nport);
     762            newProps.setProperty(RouterAddress.PROP_PORT, nport);
    761763            changed = true;
    762764        }
     
    770772        //                          And new "always" setting ignores reachability status, like
    771773        //                          "true" was in 0.7.3
    772         String ohost = newProps.getProperty(NTCPAddress.PROP_HOST);
     774        String ohost = newProps.getProperty(RouterAddress.PROP_HOST);
    773775        String enabled = _context.getProperty(PROP_I2NP_NTCP_AUTO_IP, "true").toLowerCase(Locale.US);
    774776        String name = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME);
     
    791793                return;
    792794            if (ohost == null || ! ohost.equalsIgnoreCase(nhost)) {
    793                 newProps.setProperty(NTCPAddress.PROP_HOST, nhost);
     795                newProps.setProperty(RouterAddress.PROP_HOST, nhost);
    794796                changed = true;
    795797            }
     
    803805            if (_log.shouldLog(Log.INFO))
    804806                _log.info("old: " + ohost + " config: " + name + " new: " + name);
    805             newProps.setProperty(NTCPAddress.PROP_HOST, name);
     807            newProps.setProperty(RouterAddress.PROP_HOST, name);
    806808            changed = true;
    807809        } else if (ohost == null || ohost.length() <= 0) {
     
    821823            if (oldAddr != null) {
    822824                int oldCost = oldAddr.getCost();
    823                 int newCost = NTCPAddress.DEFAULT_COST;
     825                int newCost = DEFAULT_COST;
    824826                if (TransportImpl.ADJUST_COST && !haveCapacity())
    825827                    newCost++;
     
    880882
    881883    /**
    882      *  @return current port, else NTCP configured port, else -1 (but not UDP port if auto)
     884     *  @return current IPv4 port, else NTCP configured port, else -1 (but not UDP port if auto)
    883885     */
    884886    @Override
    885887    public int getRequestedPort() {
    886         NTCPAddress addr = _myAddress;
     888        RouterAddress addr = getCurrentAddress(false);
    887889        if (addr != null) {
    888890            int port = addr.getPort();
     
    908910    @Override
    909911    public short getReachabilityStatus() {
    910         if (isAlive() && _myAddress != null) {
     912        // If we have an IPv4 address
     913        if (isAlive() && getCurrentAddress(false) != null) {
    911914                for (NTCPConnection con : _conByIdent.values()) {
    912915                    if (con.isInbound())
     
    937940        }
    938941        NTCPConnection.releaseResources();
    939         // will this work?
    940942        replaceAddress(null);
    941943    }
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    r3a49d6d rc76c800  
    15781578    public void stopListening() {
    15791579        shutdown();
    1580         // will this work?
    15811580        replaceAddress(null);
    15821581    }
Note: See TracChangeset for help on using the changeset viewer.