constants.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /// <reference types="node" />
  2. import { Duplex } from 'stream';
  3. import { Socket, SocketConnectOpts } from 'net';
  4. import { RequireOnlyOne } from './util';
  5. declare const DEFAULT_TIMEOUT = 30000;
  6. declare type SocksProxyType = 4 | 5;
  7. declare const ERRORS: {
  8. InvalidSocksCommand: string;
  9. InvalidSocksCommandForOperation: string;
  10. InvalidSocksCommandChain: string;
  11. InvalidSocksClientOptionsDestination: string;
  12. InvalidSocksClientOptionsExistingSocket: string;
  13. InvalidSocksClientOptionsProxy: string;
  14. InvalidSocksClientOptionsTimeout: string;
  15. InvalidSocksClientOptionsProxiesLength: string;
  16. NegotiationError: string;
  17. SocketClosed: string;
  18. ProxyConnectionTimedOut: string;
  19. InternalError: string;
  20. InvalidSocks4HandshakeResponse: string;
  21. Socks4ProxyRejectedConnection: string;
  22. InvalidSocks4IncomingConnectionResponse: string;
  23. Socks4ProxyRejectedIncomingBoundConnection: string;
  24. InvalidSocks5InitialHandshakeResponse: string;
  25. InvalidSocks5IntiailHandshakeSocksVersion: string;
  26. InvalidSocks5InitialHandshakeNoAcceptedAuthType: string;
  27. InvalidSocks5InitialHandshakeUnknownAuthType: string;
  28. Socks5AuthenticationFailed: string;
  29. InvalidSocks5FinalHandshake: string;
  30. InvalidSocks5FinalHandshakeRejected: string;
  31. InvalidSocks5IncomingConnectionResponse: string;
  32. Socks5ProxyRejectedIncomingBoundConnection: string;
  33. };
  34. declare const SOCKS_INCOMING_PACKET_SIZES: {
  35. Socks5InitialHandshakeResponse: number;
  36. Socks5UserPassAuthenticationResponse: number;
  37. Socks5ResponseHeader: number;
  38. Socks5ResponseIPv4: number;
  39. Socks5ResponseIPv6: number;
  40. Socks5ResponseHostname: (hostNameLength: number) => number;
  41. Socks4Response: number;
  42. };
  43. declare type SocksCommandOption = 'connect' | 'bind' | 'associate';
  44. declare enum SocksCommand {
  45. connect = 1,
  46. bind = 2,
  47. associate = 3
  48. }
  49. declare enum Socks4Response {
  50. Granted = 90,
  51. Failed = 91,
  52. Rejected = 92,
  53. RejectedIdent = 93
  54. }
  55. declare enum Socks5Auth {
  56. NoAuth = 0,
  57. GSSApi = 1,
  58. UserPass = 2
  59. }
  60. declare enum Socks5Response {
  61. Granted = 0,
  62. Failure = 1,
  63. NotAllowed = 2,
  64. NetworkUnreachable = 3,
  65. HostUnreachable = 4,
  66. ConnectionRefused = 5,
  67. TTLExpired = 6,
  68. CommandNotSupported = 7,
  69. AddressNotSupported = 8
  70. }
  71. declare enum Socks5HostType {
  72. IPv4 = 1,
  73. Hostname = 3,
  74. IPv6 = 4
  75. }
  76. declare enum SocksClientState {
  77. Created = 0,
  78. Connecting = 1,
  79. Connected = 2,
  80. SentInitialHandshake = 3,
  81. ReceivedInitialHandshakeResponse = 4,
  82. SentAuthentication = 5,
  83. ReceivedAuthenticationResponse = 6,
  84. SentFinalHandshake = 7,
  85. ReceivedFinalResponse = 8,
  86. BoundWaitingForConnection = 9,
  87. Established = 10,
  88. Disconnected = 11,
  89. Error = 99
  90. }
  91. /**
  92. * Represents a SocksProxy
  93. */
  94. declare type SocksProxy = RequireOnlyOne<{
  95. ipaddress?: string;
  96. host?: string;
  97. port: number;
  98. type: SocksProxyType;
  99. userId?: string;
  100. password?: string;
  101. }, 'host' | 'ipaddress'>;
  102. /**
  103. * Represents a remote host
  104. */
  105. interface SocksRemoteHost {
  106. host: string;
  107. port: number;
  108. }
  109. /**
  110. * SocksClient connection options.
  111. */
  112. interface SocksClientOptions {
  113. command: SocksCommandOption;
  114. destination: SocksRemoteHost;
  115. proxy: SocksProxy;
  116. timeout?: number;
  117. existing_socket?: Duplex;
  118. set_tcp_nodelay?: boolean;
  119. socket_options?: SocketConnectOpts;
  120. }
  121. /**
  122. * SocksClient chain connection options.
  123. */
  124. interface SocksClientChainOptions {
  125. command: 'connect';
  126. destination: SocksRemoteHost;
  127. proxies: SocksProxy[];
  128. timeout?: number;
  129. randomizeChain?: false;
  130. }
  131. interface SocksClientEstablishedEvent {
  132. socket: Socket;
  133. remoteHost?: SocksRemoteHost;
  134. }
  135. declare type SocksClientBoundEvent = SocksClientEstablishedEvent;
  136. interface SocksUDPFrameDetails {
  137. frameNumber?: number;
  138. remoteHost: SocksRemoteHost;
  139. data: Buffer;
  140. }
  141. export { DEFAULT_TIMEOUT, ERRORS, SocksProxyType, SocksCommand, Socks4Response, Socks5Auth, Socks5HostType, Socks5Response, SocksClientState, SocksProxy, SocksRemoteHost, SocksCommandOption, SocksClientOptions, SocksClientChainOptions, SocksClientEstablishedEvent, SocksClientBoundEvent, SocksUDPFrameDetails, SOCKS_INCOMING_PACKET_SIZES };