new: [dev] use d4-common lib for hashing
parent
6ca3ec580d
commit
231fb33d60
|
@ -21,7 +21,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
uuid "github.com/gofrs/uuid"
|
||||
d4hash "github.com/D4-project/d4-golang-utils/crypto/hash"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -258,10 +258,15 @@ func d4loadConfig(d4 *d4S) bool {
|
|||
(*d4).conf = d4params{}
|
||||
(*d4).conf.source = string(readConfFile(d4, "source"))
|
||||
(*d4).conf.destination = string(readConfFile(d4, "destination"))
|
||||
tmpu, err := uuid.FromString(string(readConfFile(d4, "uuid")))
|
||||
tmpu, err := d4hash.FromString(string(readConfFile(d4, "uuid")))
|
||||
if err != nil {
|
||||
// generate new uuid
|
||||
(*d4).conf.uuid = generateUUIDv4()
|
||||
tmp, err := d4hash.NewV4()
|
||||
(*d4).conf.uuid = tmp.Bytes()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
infof(fmt.Sprintf("UUIDv4: %s\n", (*d4).conf.uuid))
|
||||
// And push it into the conf file
|
||||
f, err := os.OpenFile((*d4).confdir+"/uuid", os.O_WRONLY, 0666)
|
||||
defer f.Close()
|
||||
|
@ -269,7 +274,7 @@ func d4loadConfig(d4 *d4S) bool {
|
|||
log.Fatal(err)
|
||||
}
|
||||
// store as canonical representation
|
||||
f.WriteString(fmt.Sprintf("%s", uuid.FromBytesOrNil((*d4).conf.uuid)) + "\n")
|
||||
f.WriteString(fmt.Sprintf("%s", d4hash.FromBytesOrNil((*d4).conf.uuid)) + "\n")
|
||||
} else {
|
||||
(*d4).conf.uuid = tmpu.Bytes()
|
||||
}
|
||||
|
@ -467,15 +472,6 @@ func validPort(port string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func generateUUIDv4() []byte {
|
||||
uuid, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
infof(fmt.Sprintf("UUIDv4: %s\n", uuid))
|
||||
return uuid.Bytes()
|
||||
}
|
||||
|
||||
func (d4w *d4Writer) Write(bs []byte) (int, error) {
|
||||
// bs is pb
|
||||
// zero out moving parts of the frame
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
module github.com/D4-project/d4-goclient
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/D4-project/d4-golang-utils v0.0.0-20190529140913-8d3df190a4b1
|
||||
github.com/gofrs/uuid v3.2.0+incompatible
|
||||
)
|
|
@ -0,0 +1,4 @@
|
|||
github.com/D4-project/d4-golang-utils v0.0.0-20190529140913-8d3df190a4b1 h1:X1MWs5hOzsiHje0BdZEU44tz7azlSRnsPYt91COPulE=
|
||||
github.com/D4-project/d4-golang-utils v0.0.0-20190529140913-8d3df190a4b1/go.mod h1:2rq8KBQnNNDocwc/49cnpaqoQA/komoSHKom7ynvqJc=
|
||||
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
|
||||
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
Loading…
Reference in New Issue