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

Method IpcGetOperation

polyamide/device/uapi.go:55–140  ·  view source on GitHub ↗

IpcGetOperation implements the WireGuard configuration protocol "get" operation. See https://www.wireguard.com/xplatform/#configuration-protocol for details.

(w io.Writer)

Source from the content-addressed store, hash-verified

53// IpcGetOperation implements the WireGuard configuration protocol "get" operation.
54// See https://www.wireguard.com/xplatform/#configuration-protocol for details.
55func (device *Device) IpcGetOperation(w io.Writer) error {
56 device.ipcMutex.RLock()
57 defer device.ipcMutex.RUnlock()
58
59 buf := byteBufferPool.Get().(*bytes.Buffer)
60 buf.Reset()
61 defer byteBufferPool.Put(buf)
62 sendf := func(format string, args ...any) {
63 fmt.Fprintf(buf, format, args...)
64 buf.WriteByte('\n')
65 }
66 keyf := func(prefix string, key *[32]byte) {
67 buf.Grow(len(key)*2 + 2 + len(prefix))
68 buf.WriteString(prefix)
69 buf.WriteByte('=')
70 const hex = "0123456789abcdef"
71 for i := 0; i < len(key); i++ {
72 buf.WriteByte(hex[key[i]>>4])
73 buf.WriteByte(hex[key[i]&0xf])
74 }
75 buf.WriteByte('\n')
76 }
77
78 func() {
79 // lock required resources
80
81 device.net.RLock()
82 defer device.net.RUnlock()
83
84 device.staticIdentity.RLock()
85 defer device.staticIdentity.RUnlock()
86
87 device.peers.RLock()
88 defer device.peers.RUnlock()
89
90 // serialize device related values
91
92 if !device.staticIdentity.privateKey.IsZero() {
93 keyf("private_key", (*[32]byte)(&device.staticIdentity.privateKey))
94 }
95
96 if device.net.port != 0 {
97 sendf("listen_port=%d", device.net.port)
98 }
99
100 if device.net.fwmark != 0 {
101 sendf("fwmark=%d", device.net.fwmark)
102 }
103
104 for _, peer := range device.peers.keyMap {
105 // Serialize peer state.
106 peer.handshake.mutex.RLock()
107 keyf("public_key", (*[32]byte)(&peer.handshake.remoteStatic))
108 keyf("preshared_key", (*[32]byte)(&peer.handshake.presharedKey))
109 peer.handshake.mutex.RUnlock()
110 sendf("protocol_version=1")
111 peer.endpoints.Lock()
112 if len(peer.endpoints.val) != 0 {

Callers 3

IpcGetMethod · 0.95
IpcHandleMethod · 0.95
BenchmarkUAPIGetFunction · 0.80

Implementers 4

NativeTunpolyamide/tun/tun_linux.go
netTunpolyamide/tun/netstack/tun.go
chTunpolyamide/tun/tuntest/tuntest.go
fakeTUNDeviceSizedpolyamide/device/device_test.go

Calls 9

ipcErrorfFunction · 0.85
PutMethod · 0.80
EntriesForPeerMethod · 0.80
DstToStringMethod · 0.65
WriteMethod · 0.65
GetMethod · 0.45
ResetMethod · 0.45
IsZeroMethod · 0.45
StringMethod · 0.45

Tested by 1

BenchmarkUAPIGetFunction · 0.64