Skip to content

Commit 166eada

Browse files
committed
Rename methods for keys RIVM-120
1 parent 7f1eab3 commit 166eada

File tree

10 files changed

+33
-33
lines changed

10 files changed

+33
-33
lines changed

cmd/genkeys/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func main() {
4545
fmt.Println("Pub:", hex.EncodeToString(newKey.pub))
4646
logger := log.New(os.Stdout, "", log.Flags())
4747
core, _ := c.New(newKey.priv, logger, nil)
48-
addr := core.AddrForKey(types.Domain{Key: newKey.pub, Name: newKey.pub})
48+
addr := core.AddrForDomain(types.Domain{Key: newKey.pub, Name: newKey.pub})
4949
fmt.Println("IP:", net.IP(addr[:]).String())
5050
}
5151
}

cmd/mesh/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,14 @@ func run(args rivArgs, sigCh chan os.Signal) {
215215
switch {
216216
case args.getaddr:
217217
if key := getNodeKey(); !key.Equal(types.Domain{}) {
218-
addr := n.core.AddrForKey(key)
218+
addr := n.core.AddrForDomain(key)
219219
ip := net.IP(addr[:])
220220
fmt.Println(ip.String())
221221
}
222222
return
223223
case args.getsnet:
224224
if key := getNodeKey(); !key.Equal(types.Domain{}) {
225-
snet := n.core.SubnetForKey(key)
225+
snet := n.core.SubnetForDomain(key)
226226
ipnet := net.IPNet{
227227
IP: append(snet[:], 0, 0, 0, 0, 0, 0, 0, 0),
228228
Mask: net.CIDRMask(len(snet)*8, 128),

contrib/mobile/mobile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (m *Mesh) GetPeersJSON() (result string) {
230230
IP string
231231
}{}
232232
for _, v := range m.core.GetPeers() {
233-
a := m.core.AddrForKey(v.Domain)
233+
a := m.core.AddrForDomain(v.Domain)
234234
ip := net.IP(a[:]).String()
235235
peers = append(peers, struct {
236236
core.PeerInfo

src/core/address.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ func (c *Core) IsValidSubnet(s Subnet) bool {
5252
return s[l-1] == prefix[l-1]|0x01
5353
}
5454

55-
// AddrForKey takes a Domain as an argument and returns an *Address.
55+
// AddrForDomain takes a Domain as an argument and returns an *Address.
5656
// This function returns nil if the key length is not ed25519.PublicKeySize.
5757
// This address begins with the contents of GetPrefix(), with the last bit set to 0 to indicate an address.
5858
// The following 8 bits are set to the number of leading 1 bits in the bitwise inverse of the public key.
59-
// The bitwise inverse of the key, excluding the leading 1 bits and the first leading 0 bit, is truncated to the appropriate length and makes up the remainder of the address.
60-
func (c *Core) AddrForKey(domain iwt.Domain) *Address {
59+
// The bitwise inverse of the Domain name, excluding the leading 1 bits and the first leading 0 bit, is truncated to the appropriate length and makes up the remainder of the address.
60+
func (c *Core) AddrForDomain(domain iwt.Domain) *Address {
6161
// 128 bit address
6262
// Begins with prefix
6363
// Next bit is a 0
@@ -102,16 +102,16 @@ func (c *Core) AddrForKey(domain iwt.Domain) *Address {
102102
return &addr
103103
}
104104

105-
// SubnetForKey takes a Domain as an argument and returns a *Subnet.
105+
// SubnetForDomain takes a Domain as an argument and returns a *Subnet.
106106
// This function returns nil if the key length is not ed25519.PublicKeySize.
107107
// The subnet begins with the address prefix, with the last bit set to 1 to indicate a prefix.
108108
// The following 8 bits are set to the number of leading 1 bits in the bitwise inverse of the key.
109-
// The bitwise inverse of the key, excluding the leading 1 bits and the first leading 0 bit, is truncated to the appropriate length and makes up the remainder of the subnet.
110-
func (c *Core) SubnetForKey(domain iwt.Domain) *Subnet {
109+
// The bitwise inverse of the Domain name bytes, excluding the leading 1 bits and the first leading 0 bit, is truncated to the appropriate length and makes up the remainder of the subnet.
110+
func (c *Core) SubnetForDomain(domain iwt.Domain) *Subnet {
111111
// Exactly as the address version, with two exceptions:
112112
// 1) The first bit after the fixed prefix is a 1 instead of a 0
113113
// 2) It's truncated to a subnet prefix length instead of 128 bits
114-
addr := c.AddrForKey(domain)
114+
addr := c.AddrForDomain(domain)
115115
if addr == nil {
116116
return nil
117117
}
@@ -124,7 +124,7 @@ func (c *Core) SubnetForKey(domain iwt.Domain) *Subnet {
124124
// GetKet returns the partial ed25519.PublicKey for the Address.
125125
// This is used for key lookup.
126126

127-
func (c *Core) GetAddressKey(a Address) iwt.Domain {
127+
func (c *Core) GetAddressDomain(a Address) iwt.Domain {
128128
var key [ed25519.PublicKeySize]byte
129129
prefix := c.GetPrefix() // nolint:staticcheck
130130
ones := int(a[len(prefix)])
@@ -152,8 +152,8 @@ func (c *Core) GetAddressKey(a Address) iwt.Domain {
152152

153153
// GetKet returns the partial ed25519.PublicKey for the Subnet.
154154
// This is used for key lookup.
155-
func (c *Core) GetSubnetKey(s Subnet) iwt.Domain {
155+
func (c *Core) GetSubnetDomain(s Subnet) iwt.Domain {
156156
var addr Address
157157
copy(addr[:], s[:])
158-
return c.GetAddressKey(addr)
158+
return c.GetAddressDomain(addr)
159159
}

src/core/address_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (c *Core) TestAddress_AddrForKey(t *testing.T) {
6565
0xfc, 0, 132, 138, 96, 79, 187, 126, 67, 132, 101, 219, 141, 182, 104, 149,
6666
}
6767

68-
if *c.AddrForKey(types.Domain{Key: publicKey, Name: publicKey}) != expectedAddress {
68+
if *c.AddrForDomain(types.Domain{Key: publicKey, Name: publicKey}) != expectedAddress {
6969
t.Fatal("invalid address returned")
7070
}
7171
}
@@ -78,7 +78,7 @@ func (c *Core) TestAddress_SubnetForKey(t *testing.T) {
7878

7979
expectedSubnet := Subnet{0xfd, 0, 132, 138, 96, 79, 187, 126}
8080

81-
if *c.SubnetForKey(types.Domain{Key: publicKey, Name: publicKey}) != expectedSubnet {
81+
if *c.SubnetForDomain(types.Domain{Key: publicKey, Name: publicKey}) != expectedSubnet {
8282
t.Fatal("invalid subnet returned")
8383
}
8484
}
@@ -95,7 +95,7 @@ func (c *Core) TestAddress_Address_GetKey(t *testing.T) {
9595
255, 255, 255, 255, 255, 255, 255, 255,
9696
}
9797

98-
if !bytes.Equal(c.GetAddressKey(address).Key, expectedPublicKey) {
98+
if !bytes.Equal(c.GetAddressDomain(address).Key, expectedPublicKey) {
9999
t.Fatal("invalid public key returned")
100100
}
101101
}
@@ -110,7 +110,7 @@ func (c *Core) TestAddress_Subnet_GetKey(t *testing.T) {
110110
255, 255, 255, 255, 255, 255, 255, 255,
111111
}
112112

113-
if !bytes.Equal(c.GetSubnetKey(subnet).Key, expectedPublicKey) {
113+
if !bytes.Equal(c.GetSubnetDomain(subnet).Key, expectedPublicKey) {
114114
t.Fatal("invalid public key returned")
115115
}
116116
}

src/core/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (c *Core) Listen(u *url.URL, sintf string) (*Listener, error) {
171171
// that application also implements either VPN functionality or deals with IP
172172
// packets specifically.
173173
func (c *Core) Address() net.IP {
174-
addr := net.IP(c.AddrForKey(c.public)[:])
174+
addr := net.IP(c.AddrForDomain(c.public)[:])
175175
return addr
176176
}
177177

@@ -181,7 +181,7 @@ func (c *Core) Address() net.IP {
181181
// that application also implements either VPN functionality or deals with IP
182182
// packets specifically.
183183
func (c *Core) Subnet() net.IPNet {
184-
subnet := c.SubnetForKey(c.public)[:]
184+
subnet := c.SubnetForDomain(c.public)[:]
185185
subnet = append(subnet, 0, 0, 0, 0, 0, 0, 0, 0)
186186
return net.IPNet{IP: subnet, Mask: net.CIDRMask(64, 128)}
187187
}

src/core/link.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (intf *link) handler(dial *linkDial) error {
193193
if intf.incoming {
194194
dir = "inbound"
195195
}
196-
remoteAddr := net.IP(intf.links.core.AddrForKey(meta.domain)[:]).String()
196+
remoteAddr := net.IP(intf.links.core.AddrForDomain(meta.domain)[:]).String()
197197
remoteStr := fmt.Sprintf("%s@%s", remoteAddr, intf.info.remote)
198198
localStr := intf.conn.LocalAddr()
199199
intf.links.core.log.Infof("Connected %s %s: %s, source %s",

src/core/proto.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func (p *protoHandler) getSelfHandler(in json.RawMessage) (interface{}, error) {
271271
if err := msg.UnmarshalJSON(info); err != nil {
272272
return nil, err
273273
}
274-
ip := net.IP(p.core.AddrForKey(req.Key)[:])
274+
ip := net.IP(p.core.AddrForDomain(req.Key)[:])
275275
res := DebugGetSelfResponse{ip.String(): msg}
276276
return res, nil
277277
}
@@ -317,7 +317,7 @@ func (p *protoHandler) getPeersHandler(in json.RawMessage) (interface{}, error)
317317
if err := msg.UnmarshalJSON(js); err != nil {
318318
return nil, err
319319
}
320-
ip := net.IP(p.core.AddrForKey(req.Key)[:])
320+
ip := net.IP(p.core.AddrForDomain(req.Key)[:])
321321
res := DebugGetPeersResponse{ip.String(): msg}
322322
return res, nil
323323
}
@@ -362,7 +362,7 @@ func (p *protoHandler) getDHTHandler(in json.RawMessage) (interface{}, error) {
362362
if err := msg.UnmarshalJSON(js); err != nil {
363363
return nil, err
364364
}
365-
ip := net.IP(p.core.AddrForKey(req.Key)[:])
365+
ip := net.IP(p.core.AddrForDomain(req.Key)[:])
366366
res := DebugGetDHTResponse{ip.String(): msg}
367367
return res, nil
368368
}

src/ipv6rwc/ipv6rwc.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ type buffer struct {
5656

5757
func (k *keyStore) init(c *core.Core) {
5858
k.core = c
59-
k.address = *c.AddrForKey(k.core.GetSelf().Domain)
60-
k.subnet = *c.SubnetForKey(k.core.GetSelf().Domain)
59+
k.address = *c.AddrForDomain(k.core.GetSelf().Domain)
60+
k.subnet = *c.SubnetForDomain(k.core.GetSelf().Domain)
6161
if err := k.core.SetOutOfBandHandler(k.oobHandler); err != nil {
6262
err = fmt.Errorf("tun.core.SetOutOfBandHander: %w", err)
6363
panic(err)
@@ -95,7 +95,7 @@ func (k *keyStore) sendToAddress(addr core.Address, bs []byte) {
9595
}
9696
})
9797
k.mutex.Unlock()
98-
k.sendKeyLookup(k.core.GetAddressKey(addr))
98+
k.sendKeyLookup(k.core.GetAddressDomain(addr))
9999
}
100100
}
101101

@@ -124,7 +124,7 @@ func (k *keyStore) sendToSubnet(subnet core.Subnet, bs []byte) {
124124
}
125125
})
126126
k.mutex.Unlock()
127-
k.sendKeyLookup(k.core.GetSubnetKey(subnet))
127+
k.sendKeyLookup(k.core.GetSubnetDomain(subnet))
128128
}
129129
}
130130

@@ -137,8 +137,8 @@ func (k *keyStore) update(key iwt.Domain) *keyInfo {
137137
if info = k.keyToInfo[kArray]; info == nil {
138138
info = new(keyInfo)
139139
info.domain = key
140-
info.address = *k.core.AddrForKey(info.domain)
141-
info.subnet = *k.core.SubnetForKey(info.domain)
140+
info.address = *k.core.AddrForDomain(info.domain)
141+
info.subnet = *k.core.SubnetForDomain(info.domain)
142142
k.keyToInfo[kArray] = info
143143
k.addrToInfo[info.address] = info
144144
k.subnetToInfo[info.subnet] = info
@@ -187,7 +187,7 @@ func (k *keyStore) oobHandler(fromKey, toKey types.Domain, data []byte) {
187187
sig := data[1:]
188188
switch data[0] {
189189
case typeKeyLookup:
190-
snet := *k.core.SubnetForKey(toKey)
190+
snet := *k.core.SubnetForDomain(toKey)
191191
if snet == k.subnet && ed25519.Verify(fromKey.Key, toKey.Key, sig) {
192192
// This is looking for at least our subnet (possibly our address)
193193
// Send a response

src/restapi/rest_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ func (a *RestServer) getApiDhtHandler(w http.ResponseWriter, r *http.Request) {
414414
dht := a.Core.GetDHT()
415415
result := make([]map[string]any, 0, len(dht))
416416
for _, d := range dht {
417-
addr := a.Core.AddrForKey(d.Domain)
417+
addr := a.Core.AddrForDomain(d.Domain)
418418
entry := map[string]any{
419419
"address": net.IP(addr[:]).String(),
420420
"key": hex.EncodeToString(d.Domain.Key),
@@ -555,7 +555,7 @@ func (a *RestServer) prepareGetPeers() []Peer {
555555
peers := a.Core.GetPeers()
556556
response := make([]Peer, 0, len(peers))
557557
for _, p := range peers {
558-
addr := a.Core.AddrForKey(p.Domain)
558+
addr := a.Core.AddrForDomain(p.Domain)
559559
entry := Peer{
560560
net.IP(addr[:]).String(),
561561
hex.EncodeToString(p.Domain.Key),

0 commit comments

Comments
 (0)