createFromConfig static method
Create a ShspPeer from a ShspPeerConfig object.
If config.socket is provided it will be used; otherwise config.rawSocket will be used to build a socket.
Implementation
static ShspPeer createFromConfig(ShspPeerInput config) {
if (config.socket != null) {
return ShspPeer(remotePeer: config.remotePeer, socket: config.socket!);
}
if (config.rawSocket != null) {
return createFromRemoteInfo(
remotePeer: config.remotePeer, rawSocket: config.rawSocket!);
}
// Fallback: create a RawDatagramSocket bound to any IPv4 port
// Note: binding is synchronous here; callers can prefer to pass a rawSocket.
final raw =
RawDatagramSocket.bind(InternetAddress.anyIPv4, 0) as RawDatagramSocket;
final messageCallbacks = MessageCallbackMapFactory.create();
final shspSocket = ShspSocketFactory.create(raw, messageCallbacks);
return ShspPeer(remotePeer: config.remotePeer, socket: shspSocket);
}