From c2c3c2894d679d703a3c595b6c73bde916d3a7a6 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 2 Jan 2024 16:06:38 -0800 Subject: [PATCH] Upgade Cwtch, Allow Unsigned APIs. Also update .drone --- .drone.yml | 17 +++++++++++------ generate/generate_bindings.go | 20 +++++++++++++++++++- go.mod | 4 ++-- go.sum | 4 ++-- quality.sh | 22 +++++++++++++--------- spec | 2 +- utils/eventHandler.go | 32 ++------------------------------ 7 files changed, 50 insertions(+), 51 deletions(-) diff --git a/.drone.yml b/.drone.yml index 333fa0d..602a8b7 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,9 +11,14 @@ steps: path: /go commands: - go install honnef.co/go/tools/cmd/staticcheck@latest - - wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/tor - - wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/torrc - - chmod a+x tor + - go install go.uber.org/nilaway/cmd/nilaway@latest + - wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/branch/master/tor/tor-0.4.8.9-linux-x86_64.tar.gz -O tor.tar.gz + - tar -xzf tor.tar.gz + - chmod a+x Tor/tor + - export PATH=$PWD/Tor/:$PATH + - export LD_LIBRARY_PATH=$PWD/Tor/ + - tor --version + - export GO111MODULE=on - git fetch --tags - go mod download - echo `git describe --tags` > VERSION @@ -21,7 +26,7 @@ steps: - export GOSUMDB="off" - name: build-linux - image: openpriv/golangxarm:1.19.1 + image: openpriv/golangxarm:1.21.5 volumes: - name: deps path: /go @@ -31,7 +36,7 @@ steps: - make linux - name: build-android - image: openpriv/android-go-mobile:2023.02 + image: openpriv/android-go-mobile:2024.01 volumes: - name: deps path: /go @@ -44,7 +49,7 @@ steps: - make android - name: build-windows - image: openpriv/mingw-go:2023.01 + image: openpriv/mingw-go:2024.01 environment: GOPATH: /go volumes: diff --git a/generate/generate_bindings.go b/generate/generate_bindings.go index 87841be..e96636e 100644 --- a/generate/generate_bindings.go +++ b/generate/generate_bindings.go @@ -146,6 +146,10 @@ func intArgPrototype(varName string) (string, string, string, string) { return fmt.Sprintf(`%s C.int`, ToSnakeCase(varName)), fmt.Sprintf(`int(%v)`, ToSnakeCase(varName)), fmt.Sprintf(`%v int`, varName), varName } +func uintArgPrototype(varName string) (string, string, string, string) { + return fmt.Sprintf(`%s C.uint`, ToSnakeCase(varName)), fmt.Sprintf(`int(%v)`, ToSnakeCase(varName)), fmt.Sprintf(`%v int`, varName), varName +} + func conversationArgPrototype(varName string) (string, string, string, string) { return intArgPrototype(varName) } @@ -235,7 +239,7 @@ func mapArgs(argsTypes []string) (string, string, string, string) { gUse = append(gUse, c4) case "int": if len(argTypeParts) != 2 { - fmt.Printf("generic bool arg must have have e.g. bool:\n") + fmt.Printf("generic int arg must have have e.g. int:\n") os.Exit(1) } c1, c2, c3, c4 := intArgPrototype(argTypeParts[1]) @@ -243,6 +247,20 @@ func mapArgs(argsTypes []string) (string, string, string, string) { c2GoArgs = append(c2GoArgs, c2) goSpec = append(goSpec, c3) gUse = append(gUse, c4) + case "uint": + if len(argTypeParts) != 2 { + fmt.Printf("generic uint arg must have have e.g. uint:\n") + os.Exit(1) + } + c1, c2, c3, c4 := uintArgPrototype(argTypeParts[1]) + cArgs = append(cArgs, c1) + c2GoArgs = append(c2GoArgs, c2) + goSpec = append(goSpec, c3) + // because of java/kotlin/android/gomobile inability to recognize unsigned integers + // we need to pretent this is a signed interface...so do the final cast here... + // this will cause bad behavior if a negative number is passed through the java + // interface...so...don't do that... + gUse = append(gUse, fmt.Sprintf("uint(%s)", c4)) case "string": if len(argTypeParts) != 2 { fmt.Printf("generic string arg must have have e.g. string:\n") diff --git a/go.mod b/go.mod index fa7f782..7bbe34d 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module git.openprivacy.ca/cwtch.im/cwtch-autobindings -go 1.19 +go 1.20 require ( - cwtch.im/cwtch v0.24.5 + cwtch.im/cwtch v0.25.0 git.openprivacy.ca/cwtch.im/server v1.4.5 git.openprivacy.ca/openprivacy/connectivity v1.11.0 git.openprivacy.ca/openprivacy/log v1.0.3 diff --git a/go.sum b/go.sum index 0391cec..286cdde 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ cwtch.im/cwtch v0.18.0/go.mod h1:StheazFFY7PKqBbEyDVLhzWW6WOat41zV0ckC240c5Y= -cwtch.im/cwtch v0.24.5 h1:Fr5F23sfCHTw95QnKTkbEkdLlcYI279imUOYdppJE70= -cwtch.im/cwtch v0.24.5/go.mod h1:o8uZBYjDS1DEHftxdYl91iMQZ2WDxlajM7Pa0ScfviI= +cwtch.im/cwtch v0.25.0 h1:39mAzuR6gDR3IBtWtA0QgZiCJKR+O+8lUZ0SGllcxRI= +cwtch.im/cwtch v0.25.0/go.mod h1:A3i92aFuhyHI2DYO2Qnvl5iqEw0Cox22pdiypHnMOy4= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/quality.sh b/quality.sh index c1040e4..e8f071a 100755 --- a/quality.sh +++ b/quality.sh @@ -3,22 +3,26 @@ echo "Checking code quality (you want to see no output here)" echo "" -echo "Vetting:" -go vet generate/* - echo "" -echo "Linting:" +echo "Running staticcheck..." -staticcheck ./generate +staticcheck ./... +# In the future we should remove include-pkgs. However, there are a few false positives in the overall go stdlib that make this +# too noisy right now, specifically assigning nil to initialize slices (safe), and using go internal context channels assigned +# nil (also safe). +# We also have one file infinite_channel.go written in a way that static analysis cannot reason about easily. So it is explictly +# ignored. +echo "Running nilaway..." +nilaway -include-pkgs="cwtch.im/cwtch,cwtch.im/tapir,git.openprivacy.ca/openprivacy/connectivity" -exclude-file-docstrings="nolint:nilaway" ./... echo "Time to format" gofmt -l -s -w . # ineffassign (https://github.com/gordonklaus/ineffassign) -echo "Checking for ineffectual assignment of errors (unchecked errors...)" -ineffassign . +# echo "Checking for ineffectual assignment of errors (unchecked errors...)" +# ineffassign . # misspell (https://github.com/client9/misspell/cmd/misspell) -echo "Checking for misspelled words..." -misspell . | grep -v "testing/" | grep -v "vendor/" | grep -v "go.sum" | grep -v ".idea" +# echo "Checking for misspelled words..." +# misspell . | grep -v "testing/" | grep -v "vendor/" | grep -v "go.sum" | grep -v ".idea" diff --git a/spec b/spec index ae02da4..5c2a54b 100644 --- a/spec +++ b/spec @@ -30,7 +30,7 @@ profile DisconnectFromPeer string:handle (json)profile EnhancedSendMessage conversation string:msg (json)profile EnhancedGetMessageById conversation message (json)profile EnhancedGetMessageByContentHash conversation string:contentHash -(json)profile EnhancedGetMessages conversation int:index int:count +(json)profile EnhancedGetMessages conversation int:index uint:count (json)profile EnhancedSendInviteMessage conversation conversation:target profile UpdateMessageAttribute conversation channel message string:attributeKey string:attributeValue diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 486a1a8..a1c8f58 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -200,7 +200,8 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { if conversationInfo.IsServer() { groupHandler := servers.FunctionalityGate() if err == nil { - knownServers = append(knownServers, groupHandler.GetServerInfo(profile, conversationInfo.Handle)) + serverInfo, _ := groupHandler.GetServerInfo(profile, conversationInfo.Handle); + knownServers = append(knownServers, serverInfo) } continue } @@ -478,41 +479,12 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { } case event.PeerStateChange: cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] - - // skip events the UI doesn't act on - if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { - return "" - } - - contact, err := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer]) - if ev.Event.Data[event.RemotePeer] == profile.GetOnion() { return "" // suppress events from our own profile... } - - // We do not know who this is...don't send any event until we see a message from them - // (at that point the conversation will have been created...) - if contact == nil || err != nil || contact.ID == 0 { - return "" - } - - // if we already know this state, suppress - if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { - return "" - } contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState case event.ServerStateChange: cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] - - // skip events the UI doesn't act on - if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { - return "" - } - - // if we already know this state, suppress - if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { - return "" - } contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState case event.TokenManagerInfo: conversations, err := profile.FetchConversations()