import {Socket} from 'net'
import {ExecuteReqeustError} from '../types/execute-request'
import {AddressInfo} from './utils'

export interface IProxyServer {
  address: string
  port: number
  handshakeTimeout: number
  rpcReplyTimeout: number
  shouldUseProxy: (data: {
    socket: Socket
    destinationInfo: AddressInfo
    originInfo: AddressInfo
  }) => boolean
  onRpc1928Reply: (data: any) => void
  onRpc1928ReplyTimeout: () => void
  onHandshakeCompleted: () => void
  onHandshakeTimeout: () => void
}

export interface ExecuteRequestThroughRemoteProxyParameters {
  originalSocket: Socket
  proxyServer: IProxyServer
  addressType: number
  address: string
  port: number
  requestBuffer: Buffer
  clientHandshakeBuffer: Buffer
  end: (rpcReply: number, args: {requestBuffer: Buffer}) => void
  onError: (error: ExecuteReqeustError) => void
  onConnect: (destination: Socket) => void
}

export interface WriteAndWaitParameters {
  socket: Socket
  data: Buffer
  timeout: number
  onTimeout: () => void
  onComplete: (data: Buffer) => void
}
