MCPcopy Create free account
hub / github.com/encodeous/nylon / main

Function main

polyamide/tun/netstack/examples/http_client.go:21–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19)
20
21func main() {
22 tun, tnet, err := netstack.CreateNetTUN(
23 []netip.Addr{netip.MustParseAddr("192.168.4.28")},
24 []netip.Addr{netip.MustParseAddr("8.8.8.8")},
25 1420)
26 if err != nil {
27 log.Panic(err)
28 }
29 dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(device.LogLevelVerbose, ""))
30 err = dev.IpcSet(`private_key=087ec6e14bbed210e7215cdc73468dfa23f080a1bfb8665b2fd809bd99d28379
31public_key=c4c8e984c5322c8184c72265b92b250fdb63688705f504ba003c88f03393cf28
32allowed_ip=0.0.0.0/0
33endpoint=127.0.0.1:58120
34`)
35 err = dev.Up()
36 if err != nil {
37 log.Panic(err)
38 }
39
40 client := http.Client{
41 Transport: &http.Transport{
42 DialContext: tnet.DialContext,
43 },
44 }
45 resp, err := client.Get("http://192.168.4.29/")
46 if err != nil {
47 log.Panic(err)
48 }
49 body, err := io.ReadAll(resp.Body)
50 if err != nil {
51 log.Panic(err)
52 }
53 log.Println(string(body))
54}

Callers

nothing calls this directly

Calls 7

IpcSetMethod · 0.95
UpMethod · 0.95
CreateNetTUNFunction · 0.92
NewDeviceFunction · 0.92
NewDefaultBindFunction · 0.92
NewLoggerFunction · 0.92
GetMethod · 0.45

Tested by

no test coverage detected