public class SelectingDatagramChannel extends ScionDatagramChannel
The class is non-public for now. It may be removed (or not) once we implement Selectors.
ScionDatagramChannel.RefreshPolicy| Modifier and Type | Field and Description |
|---|---|
protected static int |
DEFAULT_BUFFER_SIZE |
| Constructor and Description |
|---|
SelectingDatagramChannel(ScionService service) |
SelectingDatagramChannel(ScionService service,
DatagramChannel channel) |
| Modifier and Type | Method and Description |
|---|---|
C |
bind(InetSocketAddress address) |
protected void |
buildHeader(ByteBuffer buffer,
Path path,
int payloadLength,
InternalConstants.HdrTypes hdrType) |
protected DatagramChannel |
channel() |
protected void |
checkConnected(boolean requiredState) |
protected void |
checkListeners(Scmp.Message scmpMsg) |
protected void |
checkOpen() |
void |
close() |
void |
configureRemoteDispatcher(boolean hasDispatcher)
Deprecated.
Not required anymore, will be removed for 0.5.0
|
C |
connect(Path path)
Connect to a destination host.
|
C |
connect(SocketAddress addr)
Connect to a destination host.
|
void |
disconnect() |
protected void |
ensureBound() |
protected ByteBuffer |
getBufferReceive(int requiredSize) |
protected ByteBuffer |
getBufferSend(int requiredSize) |
protected int |
getCfgExpirationSafetyMargin() |
Path |
getConnectionPath()
Get the currently connected path.
|
protected InetSocketAddress |
getFirstHopAddress(ByteBuffer buffer,
InetSocketAddress srcAddress) |
InetSocketAddress |
getLocalAddress()
Returns the local address.
|
protected InetAddress |
getLocalAddressForSend(Path path) |
protected int |
getLocalPortForSend() |
<T> T |
getOption(SocketOption<T> option) |
InetSocketAddress |
getOverrideSourceAddress() |
PathPolicy |
getPathPolicy() |
InetSocketAddress |
getRemoteAddress()
Returns the remote address.
|
ScionService |
getService()
Return the ScionService used by this channel.
|
int |
getTimeOut() |
boolean |
isBlocking() |
boolean |
isConnected() |
boolean |
isOpen() |
protected ReentrantLock |
readLock() |
ScionSocketAddress |
receive(ByteBuffer userBuffer) |
protected static InternalConstants.HdrTypes |
receiveExtensionHeader(ByteBuffer buffer,
InternalConstants.HdrTypes hdrType) |
protected ResponsePath |
receiveFromChannel(ByteBuffer buffer,
InternalConstants.HdrTypes expectedHdrType) |
protected void |
receiveScmp(ByteBuffer buffer,
Path path) |
protected int |
sendRaw(ByteBuffer buffer,
Path path) |
<T> C |
setOption(SocketOption<T> option,
T t) |
void |
setOverrideSourceAddress(InetSocketAddress address)
This allows overriding the source address in SCION headers.
|
void |
setPathPolicy(PathPolicy pathPolicy)
Set the path policy.
|
Consumer<Scmp.ErrorMessage> |
setScmpErrorListener(Consumer<Scmp.ErrorMessage> listener)
The listener will be called for every SCMP error message that is received.
|
void |
setTimeOut(int timeoutMilliseconds) |
protected Object |
stateLock() |
protected void |
updateConnection(RequestPath newPath,
boolean mustBeConnected) |
protected boolean |
validate(ByteBuffer buffer) |
protected ReentrantLock |
writeLock() |
configureBlocking, getMappedPath, getMappedPath, open, open, open, read, send, send, writeprotected static final int DEFAULT_BUFFER_SIZE
public SelectingDatagramChannel(ScionService service) throws IOException
IOExceptionpublic SelectingDatagramChannel(ScionService service, DatagramChannel channel) throws IOException
IOExceptionpublic void setTimeOut(int timeoutMilliseconds)
public int getTimeOut()
public ScionSocketAddress receive(ByteBuffer userBuffer) throws IOException
receive in class ScionDatagramChannelIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface ChannelIOExceptionpublic boolean isBlocking()
public PathPolicy getPathPolicy()
public void setPathPolicy(PathPolicy pathPolicy) throws IOException
PathPolicy.DEFAULT. If the
channel is connected, this method will request a new path using the new policy.
After initially setting the path policy, it is used to request a new path during write() and send() whenever a path turns out to be close to expiration.
pathPolicy - the new path policyIOExceptionPathPolicy.DEFAULTpublic ScionService getService()
ScionDatagramChannel.open(ScionService).protected DatagramChannel channel()
public C bind(InetSocketAddress address) throws IOException
IOExceptionprotected void ensureBound()
throws IOException
IOExceptionpublic InetSocketAddress getLocalAddress() throws IOException
IOException - If an I/O error occursDatagramChannel.getLocalAddress()public InetSocketAddress getRemoteAddress() throws IOException
IOException - If an I/O error occursDatagramChannel.getRemoteAddress(),
connect(SocketAddress),
connect(Path)public void disconnect()
throws IOException
IOExceptionpublic boolean isOpen()
public C connect(SocketAddress addr) throws IOException
NB: A SCION channel will internally connect to the next border router (first hop) instead of
the remote host.
If the address is an instance of ScionSocketAddress then connect will use the path
associated with the address, see connect(Path).
NB: This method does internally not call DatagramChannel.connect(), instead it calls bind(). That means this method
does NOT perform any additional security checks associated with connect(), only those
associated with bind().
addr - Address of remote host.IOException - for example when the first hop (border router) cannot be connected.public C connect(Path path) throws IOException
NB: This method does internally not call DatagramChannel.connect(SocketAddress). That means this method does NOT
perform any additional security checks associated with connect(). It will however perform a
`bind(null)` unless the channel is already bound.
"connect()" is understood to provide connect to a destination address (IP+port).
- send()ing packet to another destination will cause an Exception.
- packets received from a different destination will be dropped.
- connecting to a given Path only connects to the destination address, the path (route) itself
may change, i.e. different border routers may be used.
path - Path to the remote host.IOException - for example when the first hop (border router) cannot be connected.public Path getConnectionPath()
connect(Path) and
may be refreshed when expired.protected ResponsePath receiveFromChannel(ByteBuffer buffer, InternalConstants.HdrTypes expectedHdrType) throws IOException
IOExceptionprotected InetSocketAddress getFirstHopAddress(ByteBuffer buffer, InetSocketAddress srcAddress)
protected static InternalConstants.HdrTypes receiveExtensionHeader(ByteBuffer buffer, InternalConstants.HdrTypes hdrType)
protected void receiveScmp(ByteBuffer buffer, Path path)
protected void checkListeners(Scmp.Message scmpMsg)
@Deprecated public void configureRemoteDispatcher(boolean hasDispatcher)
Calling this method sets an internal flag that forces the destination port of intra-AS packets to be 30041 independent of the UDP-overlay port. This flag has no effect for inter-AS packets or if the overlay port is already 30041.
hasDispatcher - Set to 'true' if remote end-host uses a dispatcher and requires using port
30041.public void setOverrideSourceAddress(InetSocketAddress address)
address - The external source addresspublic InetSocketAddress getOverrideSourceAddress()
protected InetAddress getLocalAddressForSend(Path path) throws IOException
IOExceptionprotected int getLocalPortForSend()
throws IOException
IOExceptionprotected int sendRaw(ByteBuffer buffer, Path path) throws IOException
IOExceptionpublic Consumer<Scmp.ErrorMessage> setScmpErrorListener(Consumer<Scmp.ErrorMessage> listener)
listener - A consumer for error messages. Use 'null' to deregister the listener.protected void checkOpen()
throws ClosedChannelException
ClosedChannelExceptionprotected void checkConnected(boolean requiredState)
public boolean isConnected()
public <T> T getOption(SocketOption<T> option) throws IOException
IOExceptionpublic <T> C setOption(SocketOption<T> option, T t) throws IOException
IOExceptionprotected int getCfgExpirationSafetyMargin()
protected final ByteBuffer getBufferSend(int requiredSize)
requiredSize - minimum required buffer sizeprotected final ByteBuffer getBufferReceive(int requiredSize)
requiredSize - minimum required buffer sizeprotected void buildHeader(ByteBuffer buffer, Path path, int payloadLength, InternalConstants.HdrTypes hdrType) throws IOException
buffer - The output bufferpath - pathpayloadLength - payload lengthhdrType - Header type e.g. SCMPIOException - in case of IOException.protected void updateConnection(RequestPath newPath, boolean mustBeConnected) throws IOException
IOExceptionprotected boolean validate(ByteBuffer buffer) throws ScionException
ScionExceptionprotected ReentrantLock readLock()
protected ReentrantLock writeLock()
protected Object stateLock()
Copyright © 2024. All rights reserved.