import (
"crypto/subtle"
"encoding/hex"
+ "errors"
"io/ioutil"
"log"
"os"
type PeerConf struct {
Id *PeerId
Timeout time.Duration
- Noncediff int
NoiseEnable bool
CPR int
// This is passphrase verifier
}
available := make(map[PeerId]bool)
for _, peerId := range peerIds {
- id := IDDecode(peerId)
- if id == nil {
+ id, err := IDDecode(peerId)
+ if err != nil {
continue
}
available[*id] = true
if dummyConf != nil {
return dummyConf
}
- conf := PeerConf{Id: id, Noncediff: 1, NoiseEnable: false, CPR: 0}
+ conf := PeerConf{Id: id, NoiseEnable: false, CPR: 0}
peerPath := path.Join(PeersPath, id.String())
verPath := path.Join(peerPath, "verifier")
}
conf.Timeout = time.Second * time.Duration(timeout)
- if val, err := readIntFromFile(path.Join(peerPath, "noncediff")); err == nil {
- conf.Noncediff = val
- }
if val, err := readIntFromFile(path.Join(peerPath, "noise")); err == nil && val == 1 {
conf.NoiseEnable = true
}
// Decode identification string.
// It must be 32 hexadecimal characters long.
-// If it is not the valid one, then return nil.
-func IDDecode(raw string) *PeerId {
+func IDDecode(raw string) (*PeerId, error) {
if len(raw) != IDSize*2 {
- return nil
+ return nil, errors.New("ID must be 32 characters long")
}
idDecoded, err := hex.DecodeString(raw)
if err != nil {
- return nil
+ return nil, errors.New("ID must contain hexadecimal characters only")
}
idP := new([IDSize]byte)
copy(idP[:], idDecoded)
id := PeerId(*idP)
- return &id
+ return &id, nil
}