forked from I2P_Developers/i2p.i2p
Transport: Add NTCPConnection.getRemoteIP()
to match SSU PeerState method
This commit is contained in:
@@ -666,10 +666,9 @@ class EventPumper implements Runnable {
|
||||
if (buf != null)
|
||||
releaseBuf(buf);
|
||||
if (con.isInbound() && con.getMessagesReceived() <= 0) {
|
||||
InetAddress addr = chan.socket().getInetAddress();
|
||||
byte[] ip = con.getRemoteIP();
|
||||
int count;
|
||||
if (addr != null) {
|
||||
byte[] ip = addr.getAddress();
|
||||
if (ip != null) {
|
||||
ByteArray ba = new ByteArray(ip);
|
||||
count = _blockedIPs.increment(ba);
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
|
@@ -179,8 +179,7 @@ class InboundEstablishState extends EstablishBase implements NTCP2Payload.Payloa
|
||||
*/
|
||||
private boolean verifyInbound(Hash aliceHash) {
|
||||
// get inet-addr
|
||||
InetAddress addr = this._con.getChannel().socket().getInetAddress();
|
||||
byte[] ip = (addr == null) ? null : addr.getAddress();
|
||||
byte[] ip = _con.getRemoteIP();
|
||||
if (_context.banlist().isBanlistedForever(aliceHash)) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Dropping inbound connection from permanently banlisted peer at " + Addresses.toString(ip) + " : " + aliceHash);
|
||||
@@ -247,9 +246,8 @@ class InboundEstablishState extends EstablishBase implements NTCP2Payload.Payloa
|
||||
_log.warn("Not in our network: " + alice, new Exception());
|
||||
// So next time we will not accept the con from this IP,
|
||||
// rather than doing the whole handshake
|
||||
InetAddress addr = _con.getChannel().socket().getInetAddress();
|
||||
if (addr != null) {
|
||||
byte[] ip = addr.getAddress();
|
||||
byte[] ip = _con.getRemoteIP();
|
||||
if (ip != null) {
|
||||
_context.blocklist().add(ip);
|
||||
}
|
||||
_transport.markUnreachable(aliceHash);
|
||||
@@ -349,11 +347,10 @@ class InboundEstablishState extends EstablishBase implements NTCP2Payload.Payloa
|
||||
// network ID cross-check, proposal 147, as of 0.9.42
|
||||
v = options[0] & 0xff;
|
||||
if (v != 0 && v != _context.router().getNetworkID()) {
|
||||
InetAddress addr = _con.getChannel().socket().getInetAddress();
|
||||
if (addr != null) {
|
||||
byte[] ip = _con.getRemoteIP();
|
||||
if (ip != null) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Dropping inbound connection from wrong network: " + addr);
|
||||
byte[] ip = addr.getAddress();
|
||||
_log.warn("Dropping inbound connection from wrong network: " + Addresses.toString(ip));
|
||||
// So next time we will not accept the con from this IP
|
||||
_context.blocklist().add(ip);
|
||||
}
|
||||
|
@@ -287,6 +287,19 @@ public class NTCPConnection implements Closeable {
|
||||
_chan.socket().getInetAddress() instanceof Inet6Address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null if unknown
|
||||
* @since 0.9.53
|
||||
*/
|
||||
public byte[] getRemoteIP() {
|
||||
if (_chan == null)
|
||||
return null;
|
||||
InetAddress addr = _chan.socket().getInetAddress();
|
||||
if (addr == null)
|
||||
return null;
|
||||
return addr.getAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Only valid during establishment;
|
||||
* replaced with EstablishState.VERIFIED or FAILED afterward
|
||||
|
Reference in New Issue
Block a user