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

Function main

polyamide/tun/netstack/examples/http_server.go:22–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20)
21
22func main() {
23 tun, tnet, err := netstack.CreateNetTUN(
24 []netip.Addr{netip.MustParseAddr("192.168.4.29")},
25 []netip.Addr{netip.MustParseAddr("8.8.8.8"), netip.MustParseAddr("8.8.4.4")},
26 1420,
27 )
28 if err != nil {
29 log.Panic(err)
30 }
31 dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(device.LogLevelVerbose, ""))
32 dev.IpcSet(`private_key=003ed5d73b55806c30de3f8a7bdab38af13539220533055e635690b8b87ad641
33listen_port=58120
34public_key=f928d4f6c1b86c12f2562c10b07c555c5c57fd00f59e90c8d8d88767271cbf7c
35allowed_ip=192.168.4.28/32
36persistent_keepalive_interval=25
37`)
38 dev.Up()
39 listener, err := tnet.ListenTCP(&net.TCPAddr{Port: 80})
40 if err != nil {
41 log.Panicln(err)
42 }
43 http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
44 log.Printf("> %s - %s - %s", request.RemoteAddr, request.URL.String(), request.UserAgent())
45 io.WriteString(writer, "Hello from userspace TCP!")
46 })
47 err = http.Serve(listener, nil)
48 if err != nil {
49 log.Panicln(err)
50 }
51}

Callers

nothing calls this directly

Calls 8

IpcSetMethod · 0.95
UpMethod · 0.95
CreateNetTUNFunction · 0.92
NewDeviceFunction · 0.92
NewDefaultBindFunction · 0.92
NewLoggerFunction · 0.92
ListenTCPMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected