Package com.hierynomus.smbj.connection
Class Connection
- java.lang.Object
-
- com.hierynomus.smbj.common.Pooled<Connection>
-
- com.hierynomus.smbj.connection.Connection
-
- All Implemented Interfaces:
PacketReceiver<SMBPacketData<?>>,java.io.Closeable,java.lang.AutoCloseable
public class Connection extends Pooled<Connection> implements java.io.Closeable, PacketReceiver<SMBPacketData<?>>
A connection to a server.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classConnection.CancelRequestprivate static classConnection.DelegatingSMBMessageConverter
-
Field Summary
Fields Modifier and Type Field Description private SMBEventBusbusprivate SMBClientclientprivate SmbConfigconfigprivate ConnectionContextconnectionContextprivate static Connection.DelegatingSMBMessageConverterconverterprivate PacketEncryptorencryptorprivate java.util.concurrent.locks.ReentrantLocklockprivate static org.slf4j.Loggerloggerprivate SMB2MessageConvertermessageConverter(package private) OutstandingRequestsoutstandingRequestsprivate IncomingPacketHandlerpacketHandlerChainprivate PathResolverpathResolverprivate SessionTablepreauthSessionTable(package private) SequenceWindowsequenceWindow(package private) ServerListserverListprivate SessionTablesessionTableprivate Signatorysignatory(package private) TransportLayer<SMBPacket<?,?>>transport
-
Constructor Summary
Constructors Constructor Description Connection(Connection connection)Connection(SmbConfig config, SMBClient client, SMBEventBus bus, ServerList serverList)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Sessionauthenticate(AuthenticationContext authContext)Authenticate the user on this connection in order to start a (new) session.private intcalculateGrantedCredits(SMB2Packet packet, int availableCredits)voidclose()voidclose(boolean force)Close the Connection.voidconnect(java.lang.String hostname, int port)private intcreditsNeeded(int payloadSize)[MS-SMB2] 3.1.5.2 Calculating the CreditChargeSMBClientgetClient()ConnectionContextgetConnectionContext()NegotiatedProtocolgetNegotiatedProtocol()Returns the negotiated protocol details for this connection.(package private) SessionTablegetPreauthSessionTable()java.lang.StringgetRemoteHostname()(package private) SessionTablegetSessionTable()voidhandle(SMBPacketData<?> uncheckedPacket)voidhandleError(java.lang.Throwable t)private voidinit()booleanisConnected()<T extends SMB2Packet>
java.util.concurrent.Future<T>send(SMB2Packet packet)send a packet.(package private) <T extends SMB2Packet>
TsendAndReceive(SMB2Packet packet)private voidsessionLogoff(SessionLoggedOff loggedOff)voidsetMessageConverter(SMB2MessageConverter smb2Converter)
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
converter
private static final Connection.DelegatingSMBMessageConverter converter
-
packetHandlerChain
private IncomingPacketHandler packetHandlerChain
-
connectionContext
private ConnectionContext connectionContext
-
sessionTable
private SessionTable sessionTable
-
preauthSessionTable
private SessionTable preauthSessionTable
-
outstandingRequests
OutstandingRequests outstandingRequests
-
sequenceWindow
SequenceWindow sequenceWindow
-
messageConverter
private SMB2MessageConverter messageConverter
-
pathResolver
private PathResolver pathResolver
-
client
private final SMBClient client
-
serverList
final ServerList serverList
-
signatory
private Signatory signatory
-
encryptor
private PacketEncryptor encryptor
-
config
private SmbConfig config
-
transport
TransportLayer<SMBPacket<?,?>> transport
-
bus
private final SMBEventBus bus
-
lock
private final java.util.concurrent.locks.ReentrantLock lock
-
-
Constructor Detail
-
Connection
public Connection(SmbConfig config, SMBClient client, SMBEventBus bus, ServerList serverList)
-
Connection
public Connection(Connection connection)
-
-
Method Detail
-
getClient
public SMBClient getClient()
-
init
private void init()
-
connect
public void connect(java.lang.String hostname, int port) throws java.io.IOException- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
close
public void close(boolean force) throws java.io.IOExceptionClose the Connection. Ifforceis set to true, it forgoes theSession.close()operation on the open sessions, and it just calls theTransportLayer.disconnect().If
forceis set to false, the usage counter of the connection reduces with one. If the usage count drops to zero the connection will be closed.- Parameters:
force- if set, does not nicely terminate the open sessions.- Throws:
java.io.IOException- If any error occurred during close-ing.
-
authenticate
public Session authenticate(AuthenticationContext authContext)
Authenticate the user on this connection in order to start a (new) session.- Returns:
- a (new) Session that is authenticated for the user.
-
send
public <T extends SMB2Packet> java.util.concurrent.Future<T> send(SMB2Packet packet) throws TransportException
send a packet.- Parameters:
packet- SMBPacket to send- Returns:
- a Future to be used to retrieve the response packet
- Throws:
TransportException- When a transport level error occurred
-
sendAndReceive
<T extends SMB2Packet> T sendAndReceive(SMB2Packet packet) throws TransportException
- Throws:
TransportException
-
calculateGrantedCredits
private int calculateGrantedCredits(SMB2Packet packet, int availableCredits)
-
creditsNeeded
private int creditsNeeded(int payloadSize)
[MS-SMB2] 3.1.5.2 Calculating the CreditCharge
-
getNegotiatedProtocol
public NegotiatedProtocol getNegotiatedProtocol()
Returns the negotiated protocol details for this connection.- Returns:
- The negotiated protocol details
-
handle
public void handle(SMBPacketData<?> uncheckedPacket) throws TransportException
- Specified by:
handlein interfacePacketReceiver<SMBPacketData<?>>- Throws:
TransportException
-
handleError
public void handleError(java.lang.Throwable t)
- Specified by:
handleErrorin interfacePacketReceiver<SMBPacketData<?>>
-
getRemoteHostname
public java.lang.String getRemoteHostname()
-
isConnected
public boolean isConnected()
-
getConnectionContext
public ConnectionContext getConnectionContext()
-
sessionLogoff
private void sessionLogoff(SessionLoggedOff loggedOff)
-
getSessionTable
SessionTable getSessionTable()
-
getPreauthSessionTable
SessionTable getPreauthSessionTable()
-
setMessageConverter
public void setMessageConverter(SMB2MessageConverter smb2Converter)
-
-