Class NetworkConnectionImpl
- java.lang.Object
-
- com.biglybt.core.networkmanager.NetworkConnectionHelper
-
- com.biglybt.core.networkmanager.impl.NetworkConnectionImpl
-
- All Implemented Interfaces:
NetworkConnection
,NetworkConnectionBase
public class NetworkConnectionImpl extends NetworkConnectionHelper implements NetworkConnection
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
NetworkConnectionImpl.bogusTransport
-
Nested classes/interfaces inherited from interface com.biglybt.core.networkmanager.NetworkConnection
NetworkConnection.ConnectionListener
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
allow_fallback
private boolean
closed
private boolean
connect_with_crypto
(package private) ConnectionAttempt
connection_attempt
private ConnectionEndpoint
connection_endpoint
(package private) NetworkConnection.ConnectionListener
connection_listener
private int
enhanced_partition_id
private IncomingMessageQueueImpl
incoming_message_queue
(package private) boolean
is_connected
private boolean
is_incoming
private byte
is_lan_local
(package private) OutgoingMessageQueueImpl
outgoing_message_queue
private byte[][]
shared_secrets
private boolean
started
(package private) Transport
transport
private java.util.Map<java.lang.Object,java.lang.Object>
user_data
-
Constructor Summary
Constructors Constructor Description NetworkConnectionImpl(ConnectionEndpoint _target, MessageStreamEncoder encoder, MessageStreamDecoder decoder, boolean _connect_with_crypto, boolean _allow_fallback, byte[][] _shared_secrets)
Constructor for new OUTbound connection.NetworkConnectionImpl(Transport _transport, MessageStreamEncoder encoder, MessageStreamDecoder decoder)
Constructor for new INbound connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close(java.lang.String reason)
Close and shutdown this connection.void
connect(int priority, NetworkConnection.ConnectionListener listener)
Connect this connection's transport, i.e.void
connect(java.nio.ByteBuffer initial_outbound_data, int priority, NetworkConnection.ConnectionListener listener)
Transport
detachTransport()
Decouples the transport from this network connection so it can be reusedvoid
enableEnhancedMessageProcessing(boolean enable, int partition_id)
Upgrade the connection to high-speed transfer processing.ConnectionEndpoint
getEndpoint()
IncomingMessageQueue
getIncomingMessageQueue()
Get the connection's incoming message queue.int
getMssSize()
OutgoingMessageQueue
getOutgoingMessageQueue()
Get the connection's outgoing message queue.java.lang.String
getString()
Transport
getTransport()
Get the connection's data transport interface.TransportBase
getTransportBase()
Get the connection's data transport interface.java.lang.Object
getUserData(java.lang.Object key)
boolean
isClosed()
boolean
isConnected()
boolean
isIncoming()
boolean
isLANLocal()
Is the connection within the local LAN network.void
notifyOfException(java.lang.Throwable error)
Inform connection of a thrown exception.void
resetLANLocalStatus()
java.lang.Object
setUserData(java.lang.Object key, java.lang.Object value)
void
startMessageProcessing()
Begin processing incoming and outgoing message queues.java.lang.String
toString()
-
Methods inherited from class com.biglybt.core.networkmanager.NetworkConnectionHelper
addRateLimiter, getDownloadLimit, getRateLimiters, getUploadLimit, removeRateLimiter, setDownloadLimit, setUploadLimit
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.biglybt.core.networkmanager.NetworkConnectionBase
addRateLimiter, getDownloadLimit, getRateLimiters, getUploadLimit, removeRateLimiter, setDownloadLimit, setUploadLimit
-
-
-
-
Field Detail
-
connection_endpoint
private final ConnectionEndpoint connection_endpoint
-
is_incoming
private final boolean is_incoming
-
connect_with_crypto
private boolean connect_with_crypto
-
allow_fallback
private boolean allow_fallback
-
shared_secrets
private byte[][] shared_secrets
-
connection_listener
NetworkConnection.ConnectionListener connection_listener
-
is_connected
boolean is_connected
-
is_lan_local
private byte is_lan_local
-
enhanced_partition_id
private int enhanced_partition_id
-
outgoing_message_queue
final OutgoingMessageQueueImpl outgoing_message_queue
-
incoming_message_queue
private final IncomingMessageQueueImpl incoming_message_queue
-
transport
Transport transport
-
connection_attempt
volatile ConnectionAttempt connection_attempt
-
started
private boolean started
-
closed
private volatile boolean closed
-
user_data
private java.util.Map<java.lang.Object,java.lang.Object> user_data
-
-
Constructor Detail
-
NetworkConnectionImpl
public NetworkConnectionImpl(ConnectionEndpoint _target, MessageStreamEncoder encoder, MessageStreamDecoder decoder, boolean _connect_with_crypto, boolean _allow_fallback, byte[][] _shared_secrets)
Constructor for new OUTbound connection. The connection is not yet established upon instantiation; use connect() to do so.- Parameters:
_remote_address
- to connect toencoder
- default message stream encoder to use for the outgoing queuedecoder
- default message stream decoder to use for the incoming queue
-
NetworkConnectionImpl
public NetworkConnectionImpl(Transport _transport, MessageStreamEncoder encoder, MessageStreamDecoder decoder)
Constructor for new INbound connection. The connection is assumed to be already established, by the given already-connected channel.- Parameters:
_remote_channel
- connected bydata_already_read
- bytestream already read during routingencoder
- default message stream encoder to use for the outgoing queuedecoder
- default message stream decoder to use for the incoming queue
-
-
Method Detail
-
getEndpoint
public ConnectionEndpoint getEndpoint()
- Specified by:
getEndpoint
in interfaceNetworkConnectionBase
-
isIncoming
public boolean isIncoming()
- Specified by:
isIncoming
in interfaceNetworkConnectionBase
-
connect
public void connect(int priority, NetworkConnection.ConnectionListener listener)
Description copied from interface:NetworkConnection
Connect this connection's transport, i.e. establish the network connection. If this connection is already established (from an incoming connection for example), then this provides a mechanism to register the connection listener, in which case connectSuccess() will be called immediately.- Specified by:
connect
in interfaceNetworkConnection
listener
- notified on connect success or failure
-
connect
public void connect(java.nio.ByteBuffer initial_outbound_data, int priority, NetworkConnection.ConnectionListener listener)
- Specified by:
connect
in interfaceNetworkConnection
-
detachTransport
public Transport detachTransport()
Description copied from interface:NetworkConnection
Decouples the transport from this network connection so it can be reused- Specified by:
detachTransport
in interfaceNetworkConnection
- Returns:
- null if detach failed
-
close
public void close(java.lang.String reason)
Description copied from interface:NetworkConnection
Close and shutdown this connection.- Specified by:
close
in interfaceNetworkConnection
-
isClosed
public boolean isClosed()
- Specified by:
isClosed
in interfaceNetworkConnectionBase
-
notifyOfException
public void notifyOfException(java.lang.Throwable error)
Description copied from interface:NetworkConnectionBase
Inform connection of a thrown exception.- Specified by:
notifyOfException
in interfaceNetworkConnectionBase
- Parameters:
error
- exception
-
getOutgoingMessageQueue
public OutgoingMessageQueue getOutgoingMessageQueue()
Description copied from interface:NetworkConnectionBase
Get the connection's outgoing message queue.- Specified by:
getOutgoingMessageQueue
in interfaceNetworkConnectionBase
- Returns:
- outbound message queue
-
getIncomingMessageQueue
public IncomingMessageQueue getIncomingMessageQueue()
Description copied from interface:NetworkConnectionBase
Get the connection's incoming message queue.- Specified by:
getIncomingMessageQueue
in interfaceNetworkConnectionBase
- Returns:
- inbound message queue
-
startMessageProcessing
public void startMessageProcessing()
Description copied from interface:NetworkConnection
Begin processing incoming and outgoing message queues.- Specified by:
startMessageProcessing
in interfaceNetworkConnection
-
enableEnhancedMessageProcessing
public void enableEnhancedMessageProcessing(boolean enable, int partition_id)
Description copied from interface:NetworkConnection
Upgrade the connection to high-speed transfer processing.- Specified by:
enableEnhancedMessageProcessing
in interfaceNetworkConnection
- Parameters:
enable
- true for high-speed processing, false for normal processing
-
getTransport
public Transport getTransport()
Description copied from interface:NetworkConnection
Get the connection's data transport interface.- Specified by:
getTransport
in interfaceNetworkConnection
- Returns:
- the transport - MAY BE NULL if not yet fully connected
-
getTransportBase
public TransportBase getTransportBase()
Description copied from interface:NetworkConnectionBase
Get the connection's data transport interface.- Specified by:
getTransportBase
in interfaceNetworkConnectionBase
- Returns:
- the transport - MAY BE NULL if not yet fully connected
-
getMssSize
public int getMssSize()
- Specified by:
getMssSize
in interfaceNetworkConnectionBase
-
setUserData
public java.lang.Object setUserData(java.lang.Object key, java.lang.Object value)
- Specified by:
setUserData
in interfaceNetworkConnection
-
getUserData
public java.lang.Object getUserData(java.lang.Object key)
- Specified by:
getUserData
in interfaceNetworkConnection
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isConnected
public boolean isConnected()
- Specified by:
isConnected
in interfaceNetworkConnection
-
isLANLocal
public boolean isLANLocal()
Description copied from interface:NetworkConnectionBase
Is the connection within the local LAN network.- Specified by:
isLANLocal
in interfaceNetworkConnectionBase
- Returns:
- true if within LAN, false of outside the LAN segment
-
resetLANLocalStatus
public void resetLANLocalStatus()
- Specified by:
resetLANLocalStatus
in interfaceNetworkConnectionBase
-
getString
public java.lang.String getString()
- Specified by:
getString
in interfaceNetworkConnectionBase
-
-