a few select staticcheck fixes
This commit is contained in:
parent
d84735cec7
commit
d5024e2bd3
|
@ -91,7 +91,7 @@ func (ac *applicationCore) CreatePeer(name string) (*model.Profile, error) {
|
|||
|
||||
_, exists := ac.eventBuses[profile.Onion]
|
||||
if exists {
|
||||
return nil, fmt.Errorf("Error: profile for onion %v already exists", profile.Onion)
|
||||
return nil, fmt.Errorf("error: profile for onion %v already exists", profile.Onion)
|
||||
}
|
||||
|
||||
eventBus := event.NewEventManager()
|
||||
|
@ -178,7 +178,7 @@ func (app *application) AddPeerPlugin(onion string, pluginID plugins.PluginID) {
|
|||
func (ac *applicationCore) LoadProfiles(password string, timeline bool, loadProfileFn LoadProfileFn) error {
|
||||
files, err := ioutil.ReadDir(path.Join(ac.directory, "profiles"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error: cannot read profiles directory: %v", err)
|
||||
return fmt.Errorf("error: cannot read profiles directory: %v", err)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
|
|
|
@ -79,7 +79,7 @@ func (cr *contactRetry) run() {
|
|||
|
||||
case event.ACNStatus:
|
||||
prog := e.Data[event.Progress]
|
||||
if prog == "100" && cr.networkUp == false {
|
||||
if prog == "100" && !cr.networkUp {
|
||||
cr.networkUp = true
|
||||
cr.connections.Range(func(k, v interface{}) bool {
|
||||
p := v.(*contact)
|
||||
|
|
|
@ -64,7 +64,7 @@ func (nc *networkCheck) run() {
|
|||
if _, exists := nc.onionsToCheck.Load(e.Data[event.Onion]); !exists {
|
||||
log.Debugf("initiating connection check for %v", e.Data[event.Onion])
|
||||
nc.onionsToCheck.Store(e.Data[event.Onion], true)
|
||||
if time.Now().Sub(lastMessageReceived) > time.Minute {
|
||||
if time.Since(lastMessageReceived) > time.Minute {
|
||||
nc.selfTest()
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func (nc *networkCheck) run() {
|
|||
}
|
||||
case <-time.After(tickTime):
|
||||
// if we haven't received an action in the last minute...kick off a set of testing
|
||||
if time.Now().Sub(lastMessageReceived) > time.Minute {
|
||||
if time.Since(lastMessageReceived) > time.Minute {
|
||||
nc.selfTest()
|
||||
}
|
||||
}
|
||||
|
@ -165,9 +165,9 @@ func (tp *TimeoutPolicy) ExecuteAction(action func() error) error {
|
|||
c <- action()
|
||||
}()
|
||||
|
||||
tick := time.Tick(time.Duration(*tp))
|
||||
tick := time.NewTicker(time.Duration(*tp))
|
||||
select {
|
||||
case <-tick:
|
||||
case <-tick.C:
|
||||
return fmt.Errorf("ActionTimedOutError")
|
||||
case err := <-c:
|
||||
return err
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
// however for small utility use, this function which polls the app until the peer is created
|
||||
// may fill that usecase better
|
||||
func WaitGetPeer(app app2.Application, name string) peer.CwtchPeer {
|
||||
for true {
|
||||
for {
|
||||
for id := range app.ListPeers() {
|
||||
peer := app.GetPeer(id)
|
||||
localName, _ := peer.GetAttribute(attr.GetLocalScope("name"))
|
||||
|
@ -22,5 +22,4 @@ func WaitGetPeer(app app2.Application, name string) peer.CwtchPeer {
|
|||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -169,10 +169,7 @@ func (pb *pipeBridge) threeShakeClient() bool {
|
|||
if string(resp) == synack {
|
||||
stop <- true
|
||||
err := pb.writeString([]byte(ack))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return err == nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ func (em *manager) Subscribe(eventType Type, queue Queue) {
|
|||
|
||||
// Publish takes an Event and sends it to the internal eventBus where it is distributed to all Subscribers
|
||||
func (em *manager) Publish(event Event) {
|
||||
if event.EventType != "" && em.closed != true {
|
||||
if event.EventType != "" && !em.closed {
|
||||
|
||||
// Debug Events for Tracing, locked behind an environment variable
|
||||
// for now.
|
||||
|
|
2
go.mod
2
go.mod
|
@ -10,6 +10,8 @@ require (
|
|||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/struCoder/pidusage v0.1.3
|
||||
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
|
||||
golang.org/x/tools v0.1.2 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
)
|
||||
|
|
17
go.sum
17
go.sum
|
@ -52,16 +52,25 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
|
|||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/struCoder/pidusage v0.1.3 h1:pZcSa6asBE38TJtW0Nui6GeCjLTpaT/jAnNP7dUTLSQ=
|
||||
github.com/struCoder/pidusage v0.1.3/go.mod h1:pWBlW3YuSwRl6h7R5KbvA4N8oOqe9LjaKW5CwT1SPjI=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg=
|
||||
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1VADv+S/80LGJmyl1ROJ2AI=
|
||||
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
@ -69,6 +78,7 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
@ -76,6 +86,13 @@ golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
|||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA=
|
||||
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
|
|
|
@ -52,8 +52,8 @@ func NewGroup(server string) (*Group, error) {
|
|||
group.Version = CurrentGroupVersion
|
||||
group.LocalID = GenerateRandomID()
|
||||
group.Accepted = true // we are starting a group, so we assume we want to connect to it...
|
||||
if tor.IsValidHostname(server) == false {
|
||||
return nil, errors.New("Server is not a valid v3 onion")
|
||||
if !tor.IsValidHostname(server) {
|
||||
return nil, errors.New("server is not a valid v3 onion")
|
||||
}
|
||||
|
||||
group.GroupServer = server
|
||||
|
@ -251,7 +251,7 @@ func ValidateInvite(invite string) (*groups.GroupInvite, error) {
|
|||
if err == nil {
|
||||
|
||||
// Validate the Invite by first checking that the server is a valid v3 onion
|
||||
if tor.IsValidHostname(gci.ServerHost) == false {
|
||||
if !tor.IsValidHostname(gci.ServerHost) {
|
||||
return nil, errors.New("server is not a valid v3 onion")
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ func DeserializeAndVerify(bundle []byte) (*KeyBundle, error) {
|
|||
var decodedPub []byte
|
||||
decodedPub, err = base32.StdEncoding.DecodeString(strings.ToUpper(string(serverKey)))
|
||||
if err == nil && len(decodedPub) == 35 {
|
||||
if ed25519.Verify(decodedPub[:32], keyBundle.Serialize(), signature) == true {
|
||||
if ed25519.Verify(decodedPub[:32], keyBundle.Serialize(), signature) { // == true
|
||||
return keyBundle, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -307,7 +307,7 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error {
|
|||
// TODO if the key bundle is incomplete then error out. In the future we may allow servers to attest to new
|
||||
// keys or subsets of keys, but for now they must commit only to a complete set of keys required for Cwtch Groups
|
||||
// (that way we can be assured that the keybundle we store is a valid one)
|
||||
if keyBundle.HasKeyType(model.KeyTypeTokenOnion) == false || keyBundle.HasKeyType(model.KeyTypeServerOnion) == false || keyBundle.HasKeyType(model.KeyTypePrivacyPass) == false {
|
||||
if !keyBundle.HasKeyType(model.KeyTypeTokenOnion) || !keyBundle.HasKeyType(model.KeyTypeServerOnion) || !keyBundle.HasKeyType(model.KeyTypePrivacyPass) {
|
||||
return errors.New("keybundle is incomplete")
|
||||
}
|
||||
|
||||
|
@ -563,19 +563,19 @@ func (cp *cwtchPeer) RejectInvite(groupID string) {
|
|||
func (cp *cwtchPeer) Listen() {
|
||||
cp.mutex.Lock()
|
||||
defer cp.mutex.Unlock()
|
||||
if cp.listenStatus == false {
|
||||
if !cp.listenStatus {
|
||||
log.Infof("cwtchPeer Listen sending ProtocolEngineStartListen\n")
|
||||
cp.listenStatus = true
|
||||
cp.eventBus.Publish(event.NewEvent(event.ProtocolEngineStartListen, map[event.Field]string{event.Onion: cp.Profile.Onion}))
|
||||
} else {
|
||||
// protocol engine is already listening
|
||||
}
|
||||
// else protocol engine is already listening
|
||||
|
||||
}
|
||||
|
||||
// StartPeersConnections attempts to connect to peer connections
|
||||
func (cp *cwtchPeer) StartPeersConnections() {
|
||||
for _, contact := range cp.GetContacts() {
|
||||
if cp.GetContact(contact).IsServer() == false {
|
||||
if !cp.GetContact(contact).IsServer() {
|
||||
cp.PeerWithOnion(contact)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,6 @@ type engine struct {
|
|||
identity primitives.Identity
|
||||
acn connectivity.ACN
|
||||
|
||||
// Engine State
|
||||
started bool
|
||||
|
||||
// Authorization list of contacts to authorization status
|
||||
authorizations sync.Map // string(onion) => model.Authorization
|
||||
|
||||
|
@ -229,7 +226,6 @@ func (e *engine) listenFn() {
|
|||
if !e.shuttingDown {
|
||||
e.eventManager.Publish(event.NewEvent(event.ProtocolEngineStopped, map[event.Field]string{event.Identity: e.identity.Hostname(), event.Error: err.Error()}))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Shutdown tears down the eventHandler goroutine
|
||||
|
@ -277,12 +273,11 @@ func (e *engine) peerWithTokenServer(onion string, tokenServerOnion string, toke
|
|||
// We are already peered and synced so return...
|
||||
// This will only not-trigger it lastKnownSignature has been wiped, which only happens when ResyncServer is called
|
||||
// in CwtchPeer.
|
||||
if conn.IsClosed() == false && len(lastKnownSignature) != 0 {
|
||||
if !conn.IsClosed() && len(lastKnownSignature) != 0 {
|
||||
return
|
||||
} else {
|
||||
// Otherwise...we are going to rebuild the connection(which will result in a bandwidth heavy resync)...
|
||||
e.leaveServer(onion)
|
||||
}
|
||||
// Otherwise...we are going to rebuild the connection(which will result in a bandwidth heavy resync)...
|
||||
e.leaveServer(onion)
|
||||
}
|
||||
// Otherwise...let's reconnect
|
||||
}
|
||||
|
@ -455,12 +450,12 @@ func (e *engine) sendMessageToGroup(groupID string, server string, ct []byte, si
|
|||
if err == nil {
|
||||
tokenApp, ok := (conn.App()).(*TokenBoardClient)
|
||||
if ok {
|
||||
if spent, numtokens := tokenApp.Post(ct, sig); spent == false {
|
||||
if spent, numtokens := tokenApp.Post(ct, sig); !spent {
|
||||
// TODO: while this works for the spam guard, it won't work for other forms of payment...
|
||||
// Make an -inline- payment, this will hold the goroutine
|
||||
if err := tokenApp.MakePayment(); err == nil {
|
||||
// This really shouldn't fail since we now know we have the required tokens...
|
||||
if spent, _ := tokenApp.Post(ct, sig); spent == false {
|
||||
if spent, _ := tokenApp.Post(ct, sig); !spent {
|
||||
e.eventManager.Publish(event.NewEvent(event.SendMessageToGroupError, map[event.Field]string{event.GroupID: groupID, event.GroupServer: server, event.Error: err.Error(), event.Signature: base64.StdEncoding.EncodeToString(sig)}))
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -167,8 +167,7 @@ func (ta *TokenBoardClient) Post(ct []byte, sig []byte) (bool, int) {
|
|||
func (ta *TokenBoardClient) MakePayment() error {
|
||||
log.Debugf("Making a Payment %v", ta)
|
||||
id, sk := primitives.InitializeEphemeralIdentity()
|
||||
var client tapir.Service
|
||||
client = new(tor.BaseOnionService)
|
||||
client := new(tor.BaseOnionService)
|
||||
client.Init(ta.acn, sk, &id)
|
||||
|
||||
tokenApplication := new(applications.TokenApplication)
|
||||
|
@ -202,7 +201,7 @@ func (ta *TokenBoardClient) NextToken(data []byte, hostname string) (privacypass
|
|||
ta.tokenLock.Lock()
|
||||
defer ta.tokenLock.Unlock()
|
||||
if len(ta.tokens) == 0 {
|
||||
return privacypass.SpentToken{}, len(ta.tokens), errors.New("No more tokens")
|
||||
return privacypass.SpentToken{}, len(ta.tokens), errors.New("no more tokens")
|
||||
}
|
||||
token := ta.tokens[0]
|
||||
ta.tokens = ta.tokens[1:]
|
||||
|
|
Loading…
Reference in New Issue