public class ScionDatagramChannel extends Object implements ByteChannel, Closeable
| Modifier and Type | Class and Description |
|---|---|
static class |
ScionDatagramChannel.RefreshPolicy |
| Modifier and Type | Field and Description |
|---|---|
protected static int |
DEFAULT_BUFFER_SIZE |
| Modifier | Constructor and Description |
|---|---|
protected |
ScionDatagramChannel(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 |
configureBlocking(boolean block) |
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() |
Path |
getMappedPath(InetSocketAddress address)
The channel maintains mappings from input address to output paths.
|
Path |
getMappedPath(Path path)
The channel maintains mappings from input path to output paths.
|
<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.
|
boolean |
isBlocking() |
boolean |
isConnected() |
boolean |
isOpen() |
static ScionDatagramChannel |
open()
Creates a channel with the default ScionService.
|
static ScionDatagramChannel |
open(ScionService service)
Creates a channel with a specific ScionService instance.
|
static ScionDatagramChannel |
open(ScionService service,
DatagramChannel channel) |
int |
read(ByteBuffer dst)
Read data from the connected stream.
|
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) |
int |
send(ByteBuffer srcBuffer,
Path path)
Attempts to send the content of the buffer to the destinationAddress.
|
int |
send(ByteBuffer srcBuffer,
SocketAddress destination)
Attempts to send the content of the buffer to the destinationAddress.
|
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.
|
protected Object |
stateLock() |
protected void |
updateConnection(RequestPath newPath,
boolean mustBeConnected) |
protected boolean |
validate(ByteBuffer buffer) |
int |
write(ByteBuffer src)
Write the content of a ByteBuffer to a connection.
|
protected ReentrantLock |
writeLock() |
protected static final int DEFAULT_BUFFER_SIZE
protected ScionDatagramChannel(ScionService service, DatagramChannel channel) throws IOException
IOExceptionpublic static ScionDatagramChannel open() throws IOException
IOException - in case of an errorpublic static ScionDatagramChannel open(ScionService service) throws IOException
Use of 'null' is not recommended but can be used for server side channels if no topology file is available. The ScionService is required to look up and refresh paths. It is also required to determine addresses and ports of border routers.
A server side channel (a channel that only responds to packets by reversing their path) may work without a service. However, having a service allows the server to look up the correct border router port for the first hop. If no service is available, the port is determined from the incoming IP header, assuming that the border router sends and receives on the same IP/port. Unfortunately, this is not guaranteed to be the case, so using a service to look up the correct port is recommended.
service - ScionService.IOException - if an error occurspublic static ScionDatagramChannel open(ScionService service, DatagramChannel channel) throws IOException
IOExceptionpublic void configureBlocking(boolean block)
throws IOException
IOExceptionpublic ScionSocketAddress receive(ByteBuffer userBuffer) throws IOException
IOExceptionpublic int send(ByteBuffer srcBuffer, SocketAddress destination) throws IOException
srcBuffer - Data to senddestination - Destination address. This should contain a host name known to the DNS so
that the ISD/AS information can be retrieved.DatagramChannel.send(ByteBuffer,
SocketAddress).IOException - if an error occurs, e.g. if the destinationAddress is an IP address that
cannot be resolved to an ISD/AS.DatagramChannel.send(ByteBuffer, SocketAddress)public int send(ByteBuffer srcBuffer, Path path) throws IOException
srcBuffer - Data to sendpath - Path to destination. Expiration is *not* verified.DatagramChannel.send(ByteBuffer,
SocketAddress).IOException - if an error occurs, e.g. if the destinationAddress is an IP address that
cannot be resolved to an ISD/AS.DatagramChannel.send(ByteBuffer, SocketAddress)public int read(ByteBuffer dst) throws IOException
read in interface ReadableByteChanneldst - The ByteBuffer that should contain data from the stream.NotYetConnectedException - If the channel is not connected.ClosedChannelException - If the channel is closed, e.g. by calling
interrupt during read().IOException - If some IOError occurs.DatagramChannel.read(ByteBuffer),
ReadableByteChannel.read(ByteBuffer)public int write(ByteBuffer src) throws IOException
write in interface WritableByteChannelsrc - The data to sendNotYetConnectedException - If the channel is not connected.ClosedChannelException - If the channel is closed.IOException - If some IOError occurs.DatagramChannel.write(ByteBuffer[])public Path getMappedPath(InetSocketAddress address)
send(ByteBuffer, SocketAddress). The channel tries to resolve the address via
DNS TXT record to a SCION enabled address and stores the result in the mapping for future use.address - A destination addresspublic Path getMappedPath(Path path)
send(ByteBuffer, Path). If the path is valid, it is also used as actual path for
any packet sent to the destination. If the path has expired, the channel will try to find an
identical, but more recent path and store it in the mapping.path - A Pathpublic 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()
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 void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic 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.