import { Duplex, DuplexOptions } from 'readable-stream'; import { EventEmitter } from 'eventemitter3'; import type { NetSocketDriver, NetConfig } from './Net.nitro'; import { isVerbose, setVerbose } from './Logger'; declare function isIP(input: string): number; declare function isIPv4(input: string): boolean; declare function isIPv6(input: string): boolean; declare function getDefaultAutoSelectFamily(): number; declare function setDefaultAutoSelectFamily(family: number): void; /** * Initialize the network module with custom configuration. * Must be called before any socket/server operations, or the config will be ignored. * * @param config Configuration options * @param config.workerThreads Number of worker threads (0 = use CPU core count) * * @example * ```ts * import { initWithConfig } from 'react-native-nitro-net'; * * // Initialize with 4 worker threads * initWithConfig({ workerThreads: 4 }); * ``` */ declare function initWithConfig(config: NetConfig): void; export interface SocketAddressOptions { address?: string; family?: 'ipv4' | 'ipv6'; port?: number; flowlabel?: number; } export declare class SocketAddress { readonly address: string; readonly family: 'ipv4' | 'ipv6'; readonly port: number; readonly flowlabel: number; constructor(options?: SocketAddressOptions); /** * Attempts to parse a string containing a socket address. * Returns a SocketAddress if successful, or undefined if not. * * Supported formats: * - `ip:port` (e.g., `127.0.0.1:8080`, `[::1]:8080`) * - `ip` only (port defaults to 0) */ static parse(input: string): SocketAddress | undefined; } export interface BlockListRule { type: 'address' | 'range' | 'subnet'; address?: string; start?: string; end?: string; prefix?: number; family: 'ipv4' | 'ipv6'; } export declare class BlockList { private _rules; /** Returns an array of rules added to the blocklist. */ get rules(): BlockListRule[]; addAddress(address: string, family?: 'ipv4' | 'ipv6'): void; addRange(start: string, end: string, family?: 'ipv4' | 'ipv6'): void; addSubnet(net: string, prefix: number, family?: 'ipv4' | 'ipv6'): void; check(address: string, family?: 'ipv4' | 'ipv6'): boolean; /** * Serializes the BlockList to a JSON-compatible format. */ toJSON(): BlockListRule[]; /** * Creates a BlockList from a JSON array of rules. */ static fromJSON(json: BlockListRule[]): BlockList; /** * Checks if a given value is a BlockList instance. */ static isBlockList(value: unknown): value is BlockList; } export interface SocketOptions extends DuplexOptions { fd?: any; allowHalfOpen?: boolean; readable?: boolean; writable?: boolean; path?: string; socketDriver?: NetSocketDriver; remoteFamily?: string; } export declare class Socket extends Duplex { protected _driver: NetSocketDriver | undefined; connecting: boolean; protected _connected: boolean; protected _hadError: boolean; remoteAddress?: string; remotePort?: number; remoteFamily?: string; localAddress?: string; localPort?: number; bytesRead: number; bytesWritten: number; autoSelectFamilyAttemptedAddresses: string[]; private _autoSelectFamily; private _timeout; private _nativeWriteCallbacks; get localFamily(): string; get readyState(): string; get pending(): boolean; constructor(options?: SocketOptions); on(event: string | symbol, listener: (...args: any[]) => void): this; private _setupEvents; private _updateAddresses; address(): { port: number; family: string; address: string; } | null; connect(options: any, connectionListener?: () => void): this; private _connect; private _connectUnix; end(chunk?: any, encoding?: any, cb?: any): this; _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void; _read(size: number): void; _final(callback: (error?: Error | null) => void): void; destroy(reason?: Error): this; _destroy(err: Error | null, callback: (error: Error | null) => void): void; setTimeout(msecs: number, callback?: () => void): this; /** * Pause the reading of data. That is, 'data' events will not be emitted. * Useful to throttle back an upload. */ pause(): this; /** * Resume reading after a call to pause(). */ resume(): this; /** * Enable/disable the use of Nagle's algorithm. */ setNoDelay(noDelay?: boolean): this; setKeepAlive(enable?: boolean, initialDelay?: number): this; ref(): this; unref(): this; /** * Set the encoding for the socket as a Readable Stream. * Use 'utf8', 'hex', etc. */ setEncoding(encoding: BufferEncoding): this; get timeout(): number; get bufferSize(): number; resetAndDestroy(): this; } export declare class Server extends EventEmitter { private _driver; private _sockets; private _connections; private _maxConnections; private _dropMaxConnection; get maxConnections(): number; set maxConnections(value: number); get dropMaxConnection(): boolean; set dropMaxConnection(value: boolean); get listening(): boolean; constructor(options?: any, connectionListener?: (socket: Socket) => void); ref(): this; unref(): this; [Symbol.asyncDispose](): Promise; listen(port?: any, host?: any, backlog?: any, callback?: any): this; close(callback?: (err?: Error) => void): this; address(): { port: number; family: string; address: string; } | null; getConnections(cb: (err: Error | null, count: number) => void): void; } export declare function createConnection(options: any, connectionListener?: () => void): Socket; export declare const connect: typeof createConnection; export declare function createServer(options?: any, connectionListener?: (socket: Socket) => void): Server; export { isIP, isIPv4, isIPv6, getDefaultAutoSelectFamily, setDefaultAutoSelectFamily, isVerbose, setVerbose, initWithConfig, }; export type { NetConfig }; declare const _default: { Socket: typeof Socket; Server: typeof Server; SocketAddress: typeof SocketAddress; BlockList: typeof BlockList; createConnection: typeof createConnection; createServer: typeof createServer; connect: typeof createConnection; isIP: typeof isIP; isIPv4: typeof isIPv4; isIPv6: typeof isIPv6; getDefaultAutoSelectFamily: typeof getDefaultAutoSelectFamily; setDefaultAutoSelectFamily: typeof setDefaultAutoSelectFamily; setVerbose: typeof setVerbose; initWithConfig: typeof initWithConfig; }; export default _default; //# sourceMappingURL=net.d.ts.map