Class NetherNetChannel
- All Implemented Interfaces:
io.netty.channel.Channel,io.netty.channel.ChannelOutboundInvoker,io.netty.util.AttributeMap,Comparable<io.netty.channel.Channel>,org.cloudburstmc.netty.channel.TransportChannel
- Direct Known Subclasses:
NetherNetChildChannel,NetherNetClientChannel
Writes work as on RakNet: a flushed message goes to native at once and its future completes when it is
handed over, and once more than MAX_QUEUED_BYTES wait to be sent the connection ends with
TransportDisconnectReason.QUEUE_TOO_LONG. Unlike RakNet, AbstractChannel.isWritable() also turns off while
either data channel holds more than 512 KiB. A plain ByteBuf goes on the reliable channel, a
NetherNetPacket on the one it names.
Reads ignore autoRead, as on RakNet, and each message follows a NetherNetPacket.Delivery
naming its data channel. Broken framing on the reliable channel ends the connection with
TransportDisconnectReason.BAD_PACKET, a message over 8 MiB, RakNet's split budget, with
TransportDisconnectReason.SPLIT_QUEUE_TOO_LONG.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne side of the selected pair carries the address the socket uses and the candidate type it was gathered as:host,srflx,prflxorrelay.Nested classes/interfaces inherited from class io.netty.channel.AbstractChannel
io.netty.channel.AbstractChannel.AbstractUnsafeNested classes/interfaces inherited from interface io.netty.channel.Channel
io.netty.channel.Channel.Unsafe -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DefaultNetherChannelConfigprotected SocketAddressstatic final intPast this many bytes waiting in the data channels the connection ends, RakNet's default limit.protected static final io.netty.channel.ChannelMetadataprotected booleanprotected tel.schich.libdatachannel.PeerConnectionprotected tel.schich.libdatachannel.DataChannelRead off the loop byisActive(), so it cannot be plain.protected SocketAddressprotected tel.schich.libdatachannel.DataChannel -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNetherNetChannel(io.netty.channel.Channel parent, InetSocketAddress remote, InetSocketAddress local) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidactivate(tel.schich.libdatachannel.DataChannel reliable, tel.schich.libdatachannel.DataChannel unreliable) Hands this channel the data channels it carries, activating it once they are in place.protected voidStarts a new attempt, so the next failure is reportable again.protected voidCloses because the connection ended underneath this channel, first telling the pipeline why.protected voidclosePeer(@Nullable tel.schich.libdatachannel.PeerConnection peer) Tears the peer down, in the background, as deleting it waits for native workers.protected voidCloses the data channels and peer connection, dropping their listeners first.io.netty.channel.ChannelConfigconfig()protected voidReports that this connection ended before it ever carried traffic, at most once per attempt.protected final voidcountReceived(int bytes) Counts a message delivered whole.protected final voidcountSent(int bytes, int segments) Counts a message handed to a data channel insegmentssegments.protected voidprotected voiddoBind(SocketAddress localAddress) protected voiddoClose()protected voidprotected voidprotected voidprotected voiddoWrite(io.netty.channel.ChannelOutboundBuffer in) protected Objectprotected voidFireschannelActivefor a channel that activates itself instead of throughactivate(tel.schich.libdatachannel.DataChannel, tel.schich.libdatachannel.DataChannel), so it reports why the connection ends like any other.longgetPing()booleanisActive()protected booleanisCompatible(io.netty.channel.EventLoop loop) booleanisOpen()protected SocketAddressintio.netty.channel.ChannelMetadatametadata()protected voidreadDataChannel(tel.schich.libdatachannel.DataChannel channel, boolean reliable) Reads a data channel from the moment the peer opens it, since libdatachannel queues what nobody reads and blocks a native worker once 1024 messages wait.protected voidregisterMetrics(tel.schich.libdatachannel.PeerConnection peer) Registers the peer callbacks that only report metrics, so neither side has to repeat them.protected SocketAddressintThe largest message the remote accepts on a data channel, or0while unknown.tel.schich.libdatachannel.SctpStatsWhat the SCTP association under this channel reports about itself, or null while there is none.protected static intsegment(io.netty.buffer.ByteBuf framed, io.netty.buffer.ByteBufAllocator allocator, int maxPayload, Consumer<ByteBuffer> sender) Splits a message into segments carrying the countdown header, handing each tosender.The candidate pair ICE settled on, which is where the media really flows: the signaling endpoint a client dialed and the address a server saw a join from are only where the conversation started.voidsetDataChannels(tel.schich.libdatachannel.DataChannel reliable, tel.schich.libdatachannel.DataChannel unreliable) Binds the data channels this channel carries, reading any thatreadDataChannel(tel.schich.libdatachannel.DataChannel, boolean)does not already.protected voidsetRemoteAddress(SocketAddress remoteAddress) Methods inherited from class io.netty.channel.AbstractChannel
alloc, bind, bind, bytesBeforeUnwritable, bytesBeforeWritable, close, close, closeFuture, compareTo, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, doShutdownOutput, equals, eventLoop, flush, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, isWritable, localAddress, maxMessagesPerWrite, newChannelPipeline, newFailedFuture, newId, newProgressivePromise, newPromise, newSucceededFuture, newUnsafe, parent, pipeline, read, remoteAddress, toString, unsafe, validateFileRegion, voidPromise, write, write, writeAndFlush, writeAndFlushMethods inherited from class io.netty.util.DefaultAttributeMap
attr, hasAttrMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.netty.util.AttributeMap
attr, hasAttrMethods inherited from interface io.netty.channel.Channel
alloc, bytesBeforeUnwritable, bytesBeforeWritable, closeFuture, eventLoop, flush, id, isRegistered, isWritable, localAddress, parent, pipeline, read, remoteAddress, unsafeMethods inherited from interface io.netty.channel.ChannelOutboundInvoker
bind, bind, close, close, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, voidPromise, write, write, writeAndFlush, writeAndFlushMethods inherited from interface java.lang.Comparable
compareTo
-
Field Details
-
METADATA
protected static final io.netty.channel.ChannelMetadata METADATA -
MAX_QUEUED_BYTES
public static final int MAX_QUEUED_BYTESPast this many bytes waiting in the data channels the connection ends, RakNet's default limit. What the SCTP association buffers below them does not count, so only a remote that stopped reading gets here.- See Also:
-
config
-
peerConnection
protected volatile tel.schich.libdatachannel.PeerConnection peerConnection -
remoteAddress
-
localAddress
-
reliableChannel
protected volatile tel.schich.libdatachannel.DataChannel reliableChannelRead off the loop byisActive(), so it cannot be plain. -
unreliableChannel
protected tel.schich.libdatachannel.DataChannel unreliableChannel -
open
protected volatile boolean open
-
-
Constructor Details
-
NetherNetChannel
protected NetherNetChannel(io.netty.channel.Channel parent, InetSocketAddress remote, InetSocketAddress local)
-
-
Method Details
-
connectionFailed
Reports that this connection ended before it ever carried traffic, at most once per attempt. Both sides call it, so a failure counts the same whether this channel dialed out or was accepted. -
clearFailureReported
protected void clearFailureReported()Starts a new attempt, so the next failure is reportable again. -
registerMetrics
protected void registerMetrics(tel.schich.libdatachannel.PeerConnection peer) Registers the peer callbacks that only report metrics, so neither side has to repeat them. Call it once per peer connection, which on the client means again after every retry; closing the channel drops them with the peer's other listeners. -
getPing
public long getPing()- Specified by:
getPingin interfaceorg.cloudburstmc.netty.channel.TransportChannel
-
sctpStats
public tel.schich.libdatachannel.SctpStats sctpStats()What the SCTP association under this channel reports about itself, or null while there is none. Its counters are cumulative, so a rate comes from the difference between two reads.- Returns:
- The association's stats, or null
-
selectedPath
The candidate pair ICE settled on, which is where the media really flows: the signaling endpoint a client dialed and the address a server saw a join from are only where the conversation started. Once connected, a channel's remote address is the pair's remote side.- Returns:
- The selected pair, or null while there is none
-
remoteMaxMessageSize
public int remoteMaxMessageSize()The largest message the remote accepts on a data channel, or0while unknown. Larger batches are segmented before they are sent. -
maxMessageSize
public int maxMessageSize()- Specified by:
maxMessageSizein interfaceorg.cloudburstmc.netty.channel.TransportChannel
-
activate
protected void activate(tel.schich.libdatachannel.DataChannel reliable, tel.schich.libdatachannel.DataChannel unreliable) Hands this channel the data channels it carries, activating it once they are in place. Idempotent, and safe to call from a libdatachannel callback.- Parameters:
reliable- The reliable data channel, which this channel sends overunreliable- The unreliable data channel, ornullwhen the peer opened none
-
fireActive
protected void fireActive()FireschannelActivefor a channel that activates itself instead of throughactivate(tel.schich.libdatachannel.DataChannel, tel.schich.libdatachannel.DataChannel), so it reports why the connection ends like any other. Event loop only. -
setDataChannels
public void setDataChannels(tel.schich.libdatachannel.DataChannel reliable, tel.schich.libdatachannel.DataChannel unreliable) Binds the data channels this channel carries, reading any thatreadDataChannel(tel.schich.libdatachannel.DataChannel, boolean)does not already. -
readDataChannel
protected void readDataChannel(tel.schich.libdatachannel.DataChannel channel, boolean reliable) Reads a data channel from the moment the peer opens it, since libdatachannel queues what nobody reads and blocks a native worker once 1024 messages wait. Messages read beforesetDataChannels(tel.schich.libdatachannel.DataChannel, tel.schich.libdatachannel.DataChannel)binds it are delivered after channelActive, and pastMAX_EARLY_MESSAGESthe channel closes. Safe to call from a libdatachannel callback, also before this channel is registered.- Parameters:
channel- The data channel to readreliable- Whether it is the reliable one
-
closeFromTransport
protected void closeFromTransport()Closes because the connection ended underneath this channel, first telling the pipeline why. Safe to call from a libdatachannel callback. Those are registered only once the channel is, and its loop stays set after it closes, so there always is a loop to close on. -
filterOutboundMessage
- Overrides:
filterOutboundMessagein classio.netty.channel.AbstractChannel
-
doWrite
- Specified by:
doWritein classio.netty.channel.AbstractChannel- Throws:
Exception
-
countReceived
protected final void countReceived(int bytes) Counts a message delivered whole. -
countSent
protected final void countSent(int bytes, int segments) Counts a message handed to a data channel insegmentssegments. -
segment
protected static int segment(io.netty.buffer.ByteBuf framed, io.netty.buffer.ByteBufAllocator allocator, int maxPayload, Consumer<ByteBuffer> sender) Splits a message into segments carrying the countdown header, handing each tosender.A segment is passed as a view of a pooled buffer that is released once
senderreturns, so a sender that keeps the bytes must copy them. The native send does.- Parameters:
framed- The message to split, read absolutely so its own indexes are left aloneallocator- Where the segment buffers come frommaxPayload- The most payload one segment may carry, excluding the header bytesender- Takes each segment, in order- Returns:
- How many segments were handed over
- Throws:
IllegalArgumentException- asNetherNetConstants.segmentCount(int, int), before any segment is handed over
-
doRegister
- Overrides:
doRegisterin classio.netty.channel.AbstractChannel- Throws:
Exception
-
doDeregister
- Overrides:
doDeregisterin classio.netty.channel.AbstractChannel- Throws:
Exception
-
doBind
- Specified by:
doBindin classio.netty.channel.AbstractChannel- Throws:
Exception
-
doDisconnect
- Specified by:
doDisconnectin classio.netty.channel.AbstractChannel- Throws:
Exception
-
doClose
- Specified by:
doClosein classio.netty.channel.AbstractChannel- Throws:
Exception
-
closeWebRTC
protected void closeWebRTC()Closes the data channels and peer connection, dropping their listeners first. The peer goes last, throughclosePeer(tel.schich.libdatachannel.PeerConnection), so a failing teardown cannot skip the rest. -
closePeer
protected void closePeer(@Nullable tel.schich.libdatachannel.PeerConnection peer) Tears the peer down, in the background, as deleting it waits for native workers.- Parameters:
peer- The peer, or null when there is none
-
doBeginRead
- Specified by:
doBeginReadin classio.netty.channel.AbstractChannel- Throws:
Exception
-
isCompatible
protected boolean isCompatible(io.netty.channel.EventLoop loop) - Specified by:
isCompatiblein classio.netty.channel.AbstractChannel
-
localAddress0
- Specified by:
localAddress0in classio.netty.channel.AbstractChannel
-
remoteAddress0
- Specified by:
remoteAddress0in classio.netty.channel.AbstractChannel
-
config
public io.netty.channel.ChannelConfig config()- Specified by:
configin interfaceio.netty.channel.Channel
-
isOpen
public boolean isOpen()- Specified by:
isOpenin interfaceio.netty.channel.Channel
-
isActive
public boolean isActive()- Specified by:
isActivein interfaceio.netty.channel.Channel
-
metadata
public io.netty.channel.ChannelMetadata metadata()- Specified by:
metadatain interfaceio.netty.channel.Channel
-
setRemoteAddress
-