Enhanced Permission API Spec, Upgrade Cwtch, Quality Improvements #53
|
@ -96,7 +96,9 @@ func main() {
|
|||
case "profile":
|
||||
generatedBindings = generateProfileFunction(generatedBindings, fName, args)
|
||||
case "(json)profile":
|
||||
generatedBindings = generateJsonProfileFunction(generatedBindings, fName, args)
|
||||
generatedBindings = generateJsonProfileFunction(generatedBindings, fName, args, false)
|
||||
case "(json-err)profile":
|
||||
generatedBindings = generateJsonProfileFunction(generatedBindings, fName, args, true)
|
||||
case "@profile-experiment":
|
||||
experiment := args[0]
|
||||
generatedBindings = generateExperimentalProfileFunction(generatedBindings, experiment, fName, args[1:])
|
||||
|
@ -258,7 +260,7 @@ func mapArgs(argsTypes []string) (string, string, string, string) {
|
|||
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
|
||||
// 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":
|
||||
|
@ -382,7 +384,7 @@ func {{FNAME}}({{GO_ARGS_SPEC}}) {
|
|||
return bindings
|
||||
}
|
||||
|
||||
func generateJsonProfileFunction(bindings string, name string, argsTypes []string) string {
|
||||
func generateJsonProfileFunction(bindings string, name string, argsTypes []string, handleErr bool) string {
|
||||
appPrototype := `
|
||||
//export c_{{FNAME}}
|
||||
func c_{{FNAME}}({{C_ARGS}}) *C.char {
|
||||
|
@ -392,14 +394,26 @@ func c_{{FNAME}}({{C_ARGS}}) *C.char {
|
|||
func {{FNAME}}({{GO_ARGS_SPEC}}) string {
|
||||
cwtchProfile := application.GetPeer(profile)
|
||||
if cwtchProfile != nil {
|
||||
return cwtchProfile.{{LIBNAME}}({{GO_ARG}})
|
||||
{{HANDLE_FUNC}}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
`
|
||||
|
||||
noErrorPrototype := `return cwtchProfile.{{LIBNAME}}({{GO_ARG}})`
|
||||
withErrorPrototype := `res,err := cwtchProfile.{{LIBNAME}}({{GO_ARG}})
|
||||
if err != nil {
|
||||
log.Errorf("could not {{FNAME}} %v", err)
|
||||
}
|
||||
return res`
|
||||
functionPrototype := noErrorPrototype
|
||||
if handleErr {
|
||||
functionPrototype = withErrorPrototype
|
||||
}
|
||||
|
||||
cArgs, c2GoArgs, goSpec, gUse := mapArgs(argsTypes)
|
||||
|
||||
appPrototype = strings.ReplaceAll(appPrototype, "{{HANDLE_FUNC}}", functionPrototype)
|
||||
appPrototype = strings.ReplaceAll(appPrototype, "{{FNAME}}", strings.TrimPrefix(name, "Enhanced"))
|
||||
appPrototype = strings.ReplaceAll(appPrototype, "{{LIBNAME}}", name)
|
||||
// We need to prepend a set of profile handle arguments...
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module git.openprivacy.ca/cwtch.im/cwtch-autobindings
|
|||
go 1.20
|
||||
|
||||
require (
|
||||
cwtch.im/cwtch v0.25.0
|
||||
cwtch.im/cwtch v0.26.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
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,6 +1,6 @@
|
|||
cwtch.im/cwtch v0.18.0/go.mod h1:StheazFFY7PKqBbEyDVLhzWW6WOat41zV0ckC240c5Y=
|
||||
cwtch.im/cwtch v0.25.0 h1:39mAzuR6gDR3IBtWtA0QgZiCJKR+O+8lUZ0SGllcxRI=
|
||||
cwtch.im/cwtch v0.25.0/go.mod h1:A3i92aFuhyHI2DYO2Qnvl5iqEw0Cox22pdiypHnMOy4=
|
||||
cwtch.im/cwtch v0.26.0 h1:AN5MOcWdKwzdsrcI2Lu5mQmE496Mi1eiplODfx3TKGs=
|
||||
cwtch.im/cwtch v0.26.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=
|
||||
|
|
|
@ -6,7 +6,8 @@ echo ""
|
|||
echo ""
|
||||
echo "Running staticcheck..."
|
||||
|
||||
staticcheck ./...
|
||||
staticcheck lib.go
|
||||
staticcheck ./utils/*
|
||||
|
||||
# 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
|
||||
|
@ -14,10 +15,12 @@ staticcheck ./...
|
|||
# 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" ./...
|
||||
nilaway -include-pkgs="git.openprivacy.ca/cwtch.im/cwtch-autobindings,cwtch.im/cwtch,cwtch.im/tapir,git.openprivacy.ca/openprivacy/connectivity" -exclude-errors-in-files="./templates/lib_template.go" -exclude-file-docstrings="nolint:nilaway" lib.go
|
||||
nilaway -include-pkgs="git.openprivacy.ca/cwtch.im/cwtch-autobindings,cwtch.im/cwtch,cwtch.im/tapir,git.openprivacy.ca/openprivacy/connectivity" -exclude-errors-in-files="./templates/lib_template.go" -exclude-file-docstrings="nolint:nilaway" ./utils/
|
||||
|
||||
echo "Time to format"
|
||||
gofmt -l -s -w .
|
||||
gofmt -l -s -w ./utils/*
|
||||
gofmt -l -s -w ./generate/*
|
||||
|
||||
# ineffassign (https://github.com/gordonklaus/ineffassign)
|
||||
# echo "Checking for ineffectual assignment of errors (unchecked errors...)"
|
||||
|
|
2
spec
2
spec
|
@ -22,6 +22,8 @@ profile UnblockConversation conversation
|
|||
profile DeleteConversation conversation
|
||||
profile PeerWithOnion string:handle
|
||||
profile DisconnectFromPeer string:handle
|
||||
(json-err)profile EnhancedGetConversationAccessControlList conversation
|
||||
profile EnhancedUpdateConversationAccessControlList conversation string:json
|
||||
|
||||
# Search
|
||||
(json)profile SearchConversations string:pattern
|
||||
|
|
|
@ -441,7 +441,6 @@ const (
|
|||
|
||||
func buildACN(globalSettings settings.GlobalSettings, torPath string, appDir string) (connectivity.ACN, settings.GlobalSettings, error) {
|
||||
|
||||
mrand.Seed(int64(time.Now().Nanosecond()))
|
||||
socksPort := mrand.Intn(1000) + 9600
|
||||
controlPort := socksPort + 1
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
|||
if conversationInfo.IsServer() {
|
||||
groupHandler := servers.FunctionalityGate()
|
||||
if err == nil {
|
||||
serverInfo, _ := groupHandler.GetServerInfo(profile, conversationInfo.Handle);
|
||||
serverInfo, _ := groupHandler.GetServerInfo(profile, conversationInfo.Handle)
|
||||
knownServers = append(knownServers, serverInfo)
|
||||
}
|
||||
continue
|
||||
|
@ -357,6 +357,10 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
|||
log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?")
|
||||
} else {
|
||||
profile := eh.app.GetPeer(ev.Profile)
|
||||
if profile == nil {
|
||||
log.Errorf("something has gone very wrong. profile is nil in handleProfileEvent")
|
||||
return ""
|
||||
}
|
||||
log.Debugf("New Profile Event to Handle: %v", ev)
|
||||
switch ev.Event.EventType {
|
||||
case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data
|
||||
|
@ -401,7 +405,11 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
|||
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
|
||||
profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False)
|
||||
|
||||
gci, _ := profile.GetConversationInfo(conversationID)
|
||||
gci, err := profile.GetConversationInfo(conversationID)
|
||||
if err != nil {
|
||||
log.Errorf("new message from non-existant group: %v", err)
|
||||
break
|
||||
}
|
||||
groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()]
|
||||
state := profile.GetPeerState(groupServer)
|
||||
// if syncing, don't flood with notifications
|
||||
|
@ -420,11 +428,13 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
|||
count, err := profile.GetChannelMessageCount(conversationID, 0)
|
||||
if err != nil {
|
||||
log.Errorf("error fetching channel message count %v %v", conversationID, err)
|
||||
break
|
||||
}
|
||||
|
||||
conversationInfo, err := profile.GetConversationInfo(conversationID)
|
||||
if err != nil {
|
||||
log.Errorf("error fetching conversation info for %v %v", conversationID, err)
|
||||
break
|
||||
}
|
||||
|
||||
blocked := constants.False
|
||||
|
@ -437,7 +447,11 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
|||
accepted = constants.True
|
||||
}
|
||||
|
||||
acl, _ := json.Marshal(conversationInfo.ACL)
|
||||
acl, err := json.Marshal(conversationInfo.ACL)
|
||||
if err != nil {
|
||||
log.Errorf("received invalid ACL in conversation: %v", err)
|
||||
break
|
||||
}
|
||||
|
||||
lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1)
|
||||
ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread...
|
||||
|
@ -457,8 +471,16 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
|||
groupPic := RandomGroupImage(ev.Event.Data[event.GroupID])
|
||||
ev.Event.Data[constants2.Picture] = groupPic
|
||||
|
||||
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
|
||||
conversationInfo, _ := profile.GetConversationInfo(conversationID)
|
||||
conversationID, err := strconv.Atoi(ev.Event.Data[event.ConversationID])
|
||||
if err != nil {
|
||||
log.Errorf("invalid conversation id recieved %v", err)
|
||||
break
|
||||
}
|
||||
conversationInfo, err := profile.GetConversationInfo(conversationID)
|
||||
if err != nil {
|
||||
log.Errorf("error fetching conversation info for %v %v", conversationID, err)
|
||||
break
|
||||
}
|
||||
acl, _ := json.Marshal(conversationInfo.ACL)
|
||||
ev.Event.Data["accessControlList"] = string(acl)
|
||||
case event.NewGroup:
|
||||
|
@ -469,10 +491,22 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
|||
groupPic := RandomGroupImage(invite.GroupID)
|
||||
ev.Event.Data[constants2.Picture] = groupPic
|
||||
|
||||
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
|
||||
conversationInfo, _ := profile.GetConversationInfo(conversationID)
|
||||
acl, _ := json.Marshal(conversationInfo.ACL)
|
||||
conversationID, err := strconv.Atoi(ev.Event.Data[event.ConversationID])
|
||||
if err != nil {
|
||||
log.Errorf("invalid conversation id recieved %v", err)
|
||||
break
|
||||
}
|
||||
conversationInfo, err := profile.GetConversationInfo(conversationID)
|
||||
if err != nil {
|
||||
log.Errorf("error fetching conversation info for %v %v", conversationID, err)
|
||||
break
|
||||
}
|
||||
acl, err := json.Marshal(conversationInfo.ACL)
|
||||
ev.Event.Data["accessControlList"] = string(acl)
|
||||
if err != nil {
|
||||
log.Errorf("received invalid ACL in conversation: %v", err)
|
||||
break
|
||||
}
|
||||
} else {
|
||||
log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivacy.ca/cwtch.im/cwtch", err)
|
||||
return ""
|
||||
|
@ -530,6 +564,10 @@ func unwrap(original *EventProfileEnvelope) *event.Event {
|
|||
|
||||
func (eh *EventHandler) startHandlingPeer(onion string) {
|
||||
eventBus := eh.app.GetEventBus(onion)
|
||||
if eventBus == nil {
|
||||
log.Errorf("could not start handling peer events .. event bus is nil")
|
||||
return
|
||||
}
|
||||
q := event.NewQueue()
|
||||
|
||||
eventBus.Subscribe(event.NetworkStatus, q)
|
||||
|
|
Loading…
Reference in New Issue