Skip to content

Commit b4ac029

Browse files
committed
endpoint dns to JSON
1 parent 90490cf commit b4ac029

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/peer/config.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,25 +378,16 @@ func (c *Config) GetPeerPublicKey(i int) string {
378378

379379
func (c *Config) GetPeerEndpoint(i int) string {
380380
if len(c.peers) > i {
381-
if len(c.peers[i].endpoint) > 0 {
382-
endpoint := c.peers[i].endpoint
383-
if endpoint != "" {
384-
return endpoint
385-
}
386-
387-
return ""
388-
389-
} else {
390-
endpoint := c.peers[i].config.Endpoint
391-
if endpoint != nil {
392-
return endpoint.String()
393-
}
381+
endpoint := c.peers[i].endpoint
382+
if endpoint != "" {
383+
return endpoint
384+
}
394385

395-
return ""
386+
endpoint := c.peers[i].config.Endpoint
387+
if endpoint != nil {
388+
return endpoint.String()
396389
}
397390
}
398-
399-
return ""
400391
}
401392

402393
func (c *Config) GetLocalhostIP() string {

src/peer/peer_config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ type PeerConfig struct {
1616
config wgtypes.PeerConfig
1717
privateKey *wgtypes.Key
1818
endpoint string
19+
endpointDNS string
1920
nickname string
2021
}
2122

2223
type peerConfigJSON struct {
2324
Config wgtypes.PeerConfig
2425
PrivateKey *wgtypes.Key
2526
Nickname string
27+
EndpointDNS string
2628
}
2729

2830
type PeerConfigArgs struct {
@@ -119,6 +121,7 @@ func (p *PeerConfig) MarshalJSON() ([]byte, error) {
119121
p.config,
120122
p.privateKey,
121123
p.nickname,
124+
p.endpointDNS
122125
})
123126
}
124127

@@ -133,6 +136,7 @@ func (p *PeerConfig) UnmarshalJSON(b []byte) error {
133136
p.config = tmp.Config
134137
p.privateKey = tmp.PrivateKey
135138
p.nickname = tmp.Nickname
139+
p.endpointDNS = tmp.EndpointDNS
136140

137141
return nil
138142
}

0 commit comments

Comments
 (0)