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 class
Connection.CancelRequest
private static class
Connection.DelegatingSMBMessageConverter
-
Field Summary
Fields Modifier and Type Field Description private SMBEventBus
bus
private SMBClient
client
private SmbConfig
config
private ConnectionContext
connectionContext
private static Connection.DelegatingSMBMessageConverter
converter
private PacketEncryptor
encryptor
private java.util.concurrent.locks.ReentrantLock
lock
private static org.slf4j.Logger
logger
private SMB2MessageConverter
messageConverter
(package private) OutstandingRequests
outstandingRequests
private IncomingPacketHandler
packetHandlerChain
private PathResolver
pathResolver
private SessionTable
preauthSessionTable
(package private) SequenceWindow
sequenceWindow
(package private) ServerList
serverList
private SessionTable
sessionTable
private Signatory
signatory
(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 Session
authenticate(AuthenticationContext authContext)
Authenticate the user on this connection in order to start a (new) session.private int
calculateGrantedCredits(SMB2Packet packet, int availableCredits)
void
close()
void
close(boolean force)
Close the Connection.void
connect(java.lang.String hostname, int port)
private int
creditsNeeded(int payloadSize)
[MS-SMB2] 3.1.5.2 Calculating the CreditChargeSMBClient
getClient()
ConnectionContext
getConnectionContext()
NegotiatedProtocol
getNegotiatedProtocol()
Returns the negotiated protocol details for this connection.(package private) SessionTable
getPreauthSessionTable()
java.lang.String
getRemoteHostname()
(package private) SessionTable
getSessionTable()
void
handle(SMBPacketData<?> uncheckedPacket)
void
handleError(java.lang.Throwable t)
private void
init()
boolean
isConnected()
<T extends SMB2Packet>
java.util.concurrent.Future<T>send(SMB2Packet packet)
send a packet.(package private) <T extends SMB2Packet>
TsendAndReceive(SMB2Packet packet)
private void
sessionLogoff(SessionLoggedOff loggedOff)
void
setMessageConverter(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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
close
public void close(boolean force) throws java.io.IOException
Close the Connection. Ifforce
is set to true, it forgoes theSession.close()
operation on the open sessions, and it just calls theTransportLayer.disconnect()
.If
force
is 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:
handle
in interfacePacketReceiver<SMBPacketData<?>>
- Throws:
TransportException
-
handleError
public void handleError(java.lang.Throwable t)
- Specified by:
handleError
in 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)
-
-