mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-21 02:08:40 +02:00
replace bson to gob
This commit is contained in:
parent
1a5ee744a8
commit
8845e8fbc7
1
go.mod
1
go.mod
@ -77,7 +77,6 @@ require (
|
||||
github.com/things-go/go-socks5 v0.0.4
|
||||
github.com/yusufpapurcu/wmi v1.2.4
|
||||
github.com/zcalusic/sysinfo v1.0.2
|
||||
go.mongodb.org/mongo-driver v1.16.0
|
||||
go.opentelemetry.io/otel v1.26.0
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.48.0
|
||||
go.opentelemetry.io/otel/metric v1.26.0
|
||||
|
2
go.sum
2
go.sum
@ -511,8 +511,6 @@ github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
github.com/zcalusic/sysinfo v1.0.2 h1:nwTTo2a+WQ0NXwo0BGRojOJvJ/5XKvQih+2RrtWqfxc=
|
||||
github.com/zcalusic/sysinfo v1.0.2/go.mod h1:kluzTYflRWo6/tXVMJPdEjShsbPpsFRyy+p1mBQPC30=
|
||||
go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4=
|
||||
go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
|
||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 h1:Xs2Ncz0gNihqu9iosIZ5SkBbWo5T8JhhLJFMQL1qmLI=
|
||||
|
@ -2,10 +2,9 @@ package messages
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -107,14 +106,19 @@ func MarshalHelloResponse(DomainAddress string) ([]byte, error) {
|
||||
payload := HelloResponse{
|
||||
DomainAddress: DomainAddress,
|
||||
}
|
||||
helloResponse, err := bson.Marshal(payload)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
enc := gob.NewEncoder(buf)
|
||||
|
||||
err := enc.Encode(payload)
|
||||
if err != nil {
|
||||
log.Errorf("failed to marshal hello response: %s", err)
|
||||
log.Errorf("failed to gob encode hello response: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
msg := make([]byte, 1, 1+len(helloResponse))
|
||||
|
||||
msg := make([]byte, 1, 1+buf.Len())
|
||||
msg[0] = byte(MsgTypeHelloResponse)
|
||||
msg = append(msg, helloResponse...)
|
||||
msg = append(msg, buf.Bytes()...)
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
@ -123,9 +127,12 @@ func UnmarshalHelloResponse(msg []byte) (string, error) {
|
||||
return "", fmt.Errorf("invalid 'hello response' message")
|
||||
}
|
||||
payload := HelloResponse{}
|
||||
err := bson.Unmarshal(msg[1:], &payload)
|
||||
buf := bytes.NewBuffer(msg[1:])
|
||||
dec := gob.NewDecoder(buf)
|
||||
|
||||
err := dec.Decode(&payload)
|
||||
if err != nil {
|
||||
log.Errorf("failed to unmarshal hello response: %s", err)
|
||||
log.Errorf("failed to gob decode hello response: %s", err)
|
||||
return "", err
|
||||
}
|
||||
return payload.DomainAddress, nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user