Streaming: Return I2PSocketAddress from StandardSocket methods (ticket #1321)

This commit is contained in:
zzz
2016-05-25 14:55:30 +00:00
parent 2a739f593f
commit 0e941625cf
2 changed files with 13 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import java.nio.channels.ServerSocketChannel;
import net.i2p.I2PException;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PSocketAddress;
/**
* Bridge to I2PServerSocket.
@ -99,11 +100,14 @@ class StandardServerSocket extends ServerSocket {
}
/**
* @return null always
* Port in returned SocketAddress will be zero.
*
* @return an I2PSocketAddress as of 0.9.26; prior to that, returned null
* @since implemented in 0.9.26
*/
@Override
public SocketAddress getLocalSocketAddress() {
return null;
return new I2PSocketAddress(_socket.getManager().getSession().getMyDestination(), 0);
}
@Override

View File

@ -10,6 +10,7 @@ import java.net.SocketException;
import java.nio.channels.SocketChannel;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PSocketAddress;
import net.i2p.client.streaming.I2PSocketOptions;
/**
@ -117,11 +118,12 @@ class StandardSocket extends Socket {
}
/**
* @return null always
* @return an I2PSocketAddress as of 0.9.26; prior to that, returned null
* @since implemented in 0.9.26
*/
@Override
public SocketAddress getLocalSocketAddress() {
return null;
return new I2PSocketAddress(_socket.getThisDestination(), _socket.getLocalPort());
}
/**
@ -157,11 +159,12 @@ class StandardSocket extends Socket {
}
/**
* @throws UnsupportedOperationException always
* @return an I2PSocketAddress as of 0.9.26; prior to that, threw UnsupportedOperationException
* @since implemented in 0.9.26
*/
@Override
public SocketAddress getRemoteSocketAddress() {
throw new UnsupportedOperationException();
return new I2PSocketAddress(_socket.getPeerDestination(), _socket.getPort());
}
/**