Skip to content

Commit c408d85

Browse files
committed
ncpm: add encoded proxy id
1 parent 5d20a0c commit c408d85

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

model/network_client_proxy_model.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func SignProxyId(proxyId server.Id) string {
5353
return string(b)
5454
}
5555

56-
func ParseProxyId(signedProxyId string) (proxyId server.Id, returnErr error) {
56+
func ParseSignedProxyId(signedProxyId string) (proxyId server.Id, returnErr error) {
5757
b := make([]byte, 64)
5858
var n int
5959
n, returnErr = base32.HexEncoding.Decode(b, []byte(signedProxyId))
@@ -94,6 +94,41 @@ func ParseProxyId(signedProxyId string) (proxyId server.Id, returnErr error) {
9494
return
9595
}
9696

97+
func EncodeProxyId(proxyId server.Id) string {
98+
proxyIdBytes := proxyId.Bytes()
99+
100+
var b []byte
101+
b = base32.HexEncoding.AppendEncode(b, proxyIdBytes)
102+
103+
return string(b)
104+
}
105+
106+
func ParseEncodedProxyId(encodedProxyId string) (proxyId server.Id, returnErr error) {
107+
b := make([]byte, 64)
108+
var n int
109+
n, returnErr = base32.HexEncoding.Decode(b, []byte(encodedProxyId))
110+
111+
if returnErr != nil {
112+
return
113+
}
114+
115+
if n < 16 {
116+
returnErr = fmt.Errorf("Invalid input length")
117+
return
118+
}
119+
120+
proxyId, returnErr = server.IdFromBytes(b[0:16])
121+
return
122+
}
123+
124+
func RequireEncodedProxyId(encodedProxyId string) server.Id {
125+
proxyId, err := ParseEncodedProxyId(encodedProxyId)
126+
if err != nil {
127+
panic(err)
128+
}
129+
return proxyId
130+
}
131+
97132
type ProxyDeviceMode int
98133

99134
const (
@@ -263,7 +298,7 @@ func GetProxyDeviceConfig(ctx context.Context, proxyId server.Id) *ProxyDeviceCo
263298
return &proxyDeviceConfig
264299
}
265300

266-
func GetProxyDeviceConfigByClientId(ctx context.Context, clientId server.Id, instanceId server.Id) *ProxyDeviceConfig {
301+
func GetProxyDeviceConfigForClient(ctx context.Context, clientId server.Id, instanceId server.Id) *ProxyDeviceConfig {
267302

268303
var proxyDeviceConfigJson string
269304

0 commit comments

Comments
 (0)