client

package
v0.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

README

Client Library

TCP

package main

import (
	"context"
	"io"
	"net"
	"net/http"
	"os"

	"github.com/rkonfj/toh/client"
)

func main() {
	c, err := client.NewTohClient(client.Options{
		Server: "wss://fill-in-your-server-here.toh.sh/ws",
		Key:    "112qcPA4xPxh7PQV3fyTMEkfByEEn84EjNeMmskVTBVy2aCa4ipX",
	})
	if err != nil {
		panic(err)
	}

	httpClient := &http.Client{
		Transport: &http.Transport{DialContext: c.DialContext},
	}

	resp, err := httpClient.Get("https://api64.ipify.org")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	io.Copy(os.Stdout, resp.Body)
}

UDP

package main

import (
	"context"
	"fmt"
	"net"

	"github.com/rkonfj/toh/client"
)

func main() {
	c, err := client.NewTohClient(client.Options{
		Server: "https://fill-in-your-server-here.toh.sh",
		Key:    "112qcPA4xPxh7PQV3fyTMEkfByEEn84EjNeMmskVTBVy2aCa4ipX",
	})
	if err != nil {
		panic(err)
	}

	resolver := net.Resolver{
		PreferGo: true,
		Dial:     c.DialContext,
	}

	ips, err := resolver.LookupIP(context.Background(), "ip", "www.google.com")
	if err != nil {
		panic(err)
	}
	fmt.Println(ips)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnEntry added in v0.12.4

type ConnEntry struct {
	Proto      string `json:"proto"`
	LocalAddr  string `json:"localAddr"`
	RemoteAddr string `json:"remoteAddr"`
	RemoteHost string `json:"remoteHost"`
	Nonce      byte   `json:"nonce"`
	// contains filtered or unexported fields
}

type Conntrack added in v0.12.4

type Conntrack struct {
	// contains filtered or unexported fields
}

func NewConntrack added in v0.12.4

func NewConntrack() *Conntrack

func (*Conntrack) List added in v0.12.4

func (ct *Conntrack) List() []ConnEntry

type Options

type Options struct {
	Server, Key string
	Keepalive   time.Duration
	Headers     http.Header
}

type TohClient

type TohClient struct {
	// contains filtered or unexported fields
}

func NewTohClient

func NewTohClient(options Options) (*TohClient, error)

func (*TohClient) Conntrack added in v0.12.4

func (c *TohClient) Conntrack() *Conntrack

func (*TohClient) DNSExchange

func (c *TohClient) DNSExchange(dnServer string, query *dns.Msg) (resp *dns.Msg, err error)

func (*TohClient) DialContext added in v0.10.2

func (c *TohClient) DialContext(ctx context.Context, network, addr string) (
	conn net.Conn, err error)

func (*TohClient) DialTCP

func (c *TohClient) DialTCP(ctx context.Context, addr string) (net.Conn, error)

func (*TohClient) DialUDP

func (c *TohClient) DialUDP(ctx context.Context, addr string) (net.Conn, error)

func (*TohClient) LookupIP added in v0.10.1

func (c *TohClient) LookupIP(host string) (ips []net.IP, err error)

LookupIP lookup ipv4 and ipv6

func (*TohClient) LookupIP4

func (c *TohClient) LookupIP4(host string) (ips []net.IP, err error)

LookupIP4 lookup only ipv4

func (*TohClient) LookupIP6 added in v0.10.1

func (c *TohClient) LookupIP6(host string) (ips []net.IP, err error)

LookupIP4 lookup only ipv6

func (*TohClient) Stats

func (c *TohClient) Stats() (s *api.Stats, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL