import { createServer as _tcp_server, createConnection as _tcp_connect } from 'node:net' import {net_common} from './_net_common.jsy' export default tcp_plugin export function tcp_plugin(plugin_options={}) :: const protocol = plugin_options.protocol || 'tcp' return hub => :: let tcp_api = @{} connect(...args) :: return _common_.createClient @ protocol, handler => _tcp_connect @ ...args, handler createServer(onPeer) :: return _common_.createServer @ protocol, onPeer, handler => _tcp_server @ handler codec: plugin_options.codec on_url_connect: plugin_options.on_url_connect p2p: plugin_options.p2p const _common_ = net_common @ hub, tcp_api, protocol hub[protocol] = tcp_api