tuweni / org.apache.tuweni.devp2p.v5.internal / DefaultUdpConnector

DefaultUdpConnector

class DefaultUdpConnector : UdpConnector, CoroutineScope (source)

Constructors

<init>

DefaultUdpConnector(bindAddress: InetSocketAddress, keyPair: KeyPair, selfEnr: Bytes, enrStorage: ENRStorage = DefaultENRStorage(), receiveChannel: CoroutineDatagramChannel = CoroutineDatagramChannel.open(), nodesTable: RoutingTable = RoutingTable(selfEnr), topicTable: TopicTable = TopicTable(), ticketHolder: TicketHolder = TicketHolder(), authenticationProvider: AuthenticationProvider = DefaultAuthenticationProvider(keyPair, nodesTable), packetCodec: PacketCodec = DefaultPacketCodec(keyPair, nodesTable), selfNodeRecord: EthereumNodeRecord = EthereumNodeRecord.fromRLP(selfEnr), messageListeners: MutableList<MessageObserver> = mutableListOf(), coroutineContext: CoroutineContext = Dispatchers.IO)

Properties

coroutineContext

val coroutineContext: CoroutineContext

Functions

attachObserver

fun attachObserver(observer: MessageObserver): Unit

Attach observer for listening processed messages

detachObserver

fun detachObserver(observer: MessageObserver): Unit

Remove observer for listening processed message

getAwaitingPongRecord

fun getAwaitingPongRecord(nodeId: Bytes): Bytes?

Retrieve enr of pinging node

getEnr

fun getEnr(): EthereumNodeRecord

Provides node's ENR

getEnrBytes

fun getEnrBytes(): Bytes

Provides node's ENR in RLP encoded representation

getNodeKeyPair

fun getNodeKeyPair(): KeyPair

Provides node's key pair

getNodeRecords

fun getNodeRecords(): ENRStorage

Provides enr storage of known nodes

getNodesTable

fun getNodesTable(): RoutingTable

Get kademlia routing table

getPendingMessage

fun getPendingMessage(authTag: Bytes): TrackingMessage?

Retrieve last sent message, in case if it unauthorized and node can resend with authentication header

getSessionInitiatorKey

fun getSessionInitiatorKey(nodeId: Bytes): Bytes

Provides node's session initiator key

getTicketHolder

fun getTicketHolder(): TicketHolder

Provides node's ticket holder

getTopicRegistrar

fun getTopicRegistrar(): TopicRegistrar

Provides node's topic registrar

getTopicTable

fun getTopicTable(): TopicTable

Provides node's topic table

send

suspend fun send(address: InetSocketAddress, message: UdpMessage, destNodeId: Bytes, handshakeParams: HandshakeInitParameters?): Unit

Sends udp message by socket address

start

suspend fun start(): Unit

Bootstraps receive loop for incoming message handling

started

fun started(): Boolean

Gives information about connector, whether receive loop is working

terminate

suspend fun terminate(): Unit

Shut downs both udp receive loop and sender socket

Extension Functions

asyncCompletion

fun CoroutineScope.asyncCompletion(context: CoroutineContext = Dispatchers.Default, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit): AsyncCompletion

Starts new co-routine and returns its result as an implementation of AsyncCompletion. The running co-routine is cancelled when the resulting future is cancelled or otherwise completed.

asyncResult

fun <T> CoroutineScope.asyncResult(context: CoroutineContext = Dispatchers.Default, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T): AsyncResult<T>

Starts new co-routine and returns its result as an implementation of AsyncResult. The running co-outine is cancelled when the resulting future is cancelled or otherwise completed.

retry

suspend fun <R> CoroutineScope.retry(retryDelay: Long, block: suspend (Int) -> R?): R
suspend fun <R> CoroutineScope.retry(retryDelay: Long, maxRetries: Int, block: suspend (Int) -> R?): R?
suspend fun <R> CoroutineScope.retry(retryDelay: (Int) -> Long?, block: suspend (Int) -> R?): R?

Retry a suspending block until a non-null result is obtained.