Skip to content

Commit 6412f13

Browse files
committed
refactor locker predicates
1 parent c9f0114 commit 6412f13

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

internal/locker/locker.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,30 @@ func init() {
3030

3131
// Locked returns a boolean whether or not Relay is node-locked
3232
func Locked() bool {
33-
return Fingerprint != "" // decent proxy for node-locked
33+
return PublicKey != "" && Fingerprint != "" // decent proxy for node-locked
3434
}
3535

36-
// LockedAddr returns a boolean whether or not Relay's bind address is locked
36+
// LockedFingerprint returns a boolean whether or not Relay is locked to machine fingerprint
37+
func LockedFingerprint() bool {
38+
return Fingerprint != ""
39+
}
40+
41+
// LockedPlatform returns a boolean whether or not Relay is locked to machine platform
42+
func LockedPlatform() bool {
43+
return Platform != ""
44+
}
45+
46+
// LockedHostname returns a boolean whether or not Relay is locked to machine hostname
47+
func LockedHostname() bool {
48+
return Hostname != ""
49+
}
50+
51+
// LockedIP returns a boolean whether or not Relay is locked to machine IP address
52+
func LockedIP() bool {
53+
return IP != ""
54+
}
55+
56+
// LockedAddr returns a boolean whether or not Relay's bind IP address is locked
3757
func LockedAddr() bool {
3858
return Addr != ""
3959
}
@@ -88,15 +108,15 @@ func Unlock(config Config) (*keygen.MachineFileDataset, error) {
88108
return nil, fmt.Errorf("machine file fingerprint mismatch")
89109
}
90110

91-
if Platform != "" {
111+
if LockedPlatform() {
92112
platform := runtime.GOOS + "/" + runtime.GOARCH
93113

94114
if expected, actual := Platform, platform; dataset.Machine.Platform != expected || actual != expected {
95115
return nil, fmt.Errorf("machine file platform mismatch")
96116
}
97117
}
98118

99-
if Hostname != "" {
119+
if LockedHostname() {
100120
hostname, err := os.Hostname()
101121
if err != nil {
102122
return nil, fmt.Errorf("machine could not determine hostname: %w", err)
@@ -107,7 +127,7 @@ func Unlock(config Config) (*keygen.MachineFileDataset, error) {
107127
}
108128
}
109129

110-
if IP != "" {
130+
if LockedIP() {
111131
ip, err := getPrivateIP()
112132
if err != nil {
113133
return nil, fmt.Errorf("machine could not determine ip: %w", err)

0 commit comments

Comments
 (0)