Skip to content

Commit

Permalink
Fix topics and message handling loops
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Feb 20, 2024
1 parent ec3096a commit 2706d46
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
20 changes: 10 additions & 10 deletions alias/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (
const (
defaultAliasLength = 8

_SELECT_ENTITY_NICK = "SELECT nick FROM entities WHERE did = ?"
_SELECT_ENTITY_DID = "SELECT did FROM entities WHERE nick = ?"
_SELECT_NODE_NICK = "SELECT nick FROM nodes WHERE id = ?"
_SELECT_NODE_ID = "SELECT id FROM nodes WHERE nick = ?"
_SELECT_ENTITY_NICK = "SELECT nick FROM entities WHERE did = ? or nick = ?"
_SELECT_ENTITY_DID = "SELECT did FROM entities WHERE did = ? or nick = ?"
_SELECT_NODE_NICK = "SELECT nick FROM nodes WHERE id = ? or nick = ?"
_SELECT_NODE_ID = "SELECT id FROM nodes WHERE id =? or nick = ?"
_UPSERT_ENTITY = "INSERT INTO entities (did, nick) VALUES (?, ?) ON CONFLICT(did) DO UPDATE SET nick = ?"
_UPSERT_NODE = "INSERT INTO nodes (id, nick) VALUES (?, ?) ON CONFLICT(id) DO UPDATE SET nick = ?"
_DELETE_ENTITY = "DELETE FROM entities WHERE did = ?"
_DELETE_NODE = "DELETE FROM nodes WHERE id = ?"
_DELETE_ENTITY = "DELETE FROM entities WHERE did = ? or nick = ?"
_DELETE_NODE = "DELETE FROM nodes WHERE id = ? or nick = ?"
)

var (
Expand Down Expand Up @@ -80,7 +80,7 @@ func GetEntityAlias(id string) (string, error) {

var a string

err = db.QueryRow(_SELECT_ENTITY_NICK, id).Scan(&a)
err = db.QueryRow(_SELECT_ENTITY_NICK, id, id).Scan(&a)
if err != nil {
return "", err
}
Expand All @@ -103,7 +103,7 @@ func GetEntityDID(nick string) (string, error) {

var id string

err = db.QueryRow(_SELECT_ENTITY_DID, nick).Scan(&id)
err = db.QueryRow(_SELECT_ENTITY_DID, nick, nick).Scan(&id)
if err != nil {
return "", err
}
Expand All @@ -127,7 +127,7 @@ func GetNodeAlias(id string) (string, error) {

var a string

err = db.QueryRow(_SELECT_NODE_NICK, id).Scan(&a)
err = db.QueryRow(_SELECT_NODE_NICK, id, id).Scan(&a)
if err != nil {
return "", err
}
Expand All @@ -150,7 +150,7 @@ func GetNodeID(nick string) (string, error) {

var id string

err = db.QueryRow(_SELECT_NODE_ID, nick).Scan(&id)
err = db.QueryRow(_SELECT_NODE_ID, nick, nick).Scan(&id)
if err != nil {
return "", err
}
Expand Down
5 changes: 3 additions & 2 deletions entity/actor/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ func New(d did.DID, k set.Keyset) (*Actor, error) {
}

a := &Actor{
Entity: e,
Keyset: k,
Entity: e,
Keyset: k,
Envelopes: make(chan *msg.Envelope, ENVELOPES_BUFFERSIZE),
}

a.CreateDocument(d.Id)
Expand Down
4 changes: 2 additions & 2 deletions entity/actor/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func (a *Actor) Subscribe(ctx context.Context, e *entity.Entity) {

log.Infof("Subscribing to %s as %s: ", they, me)

ctx, cancel := context.WithCancel(ctx)
defer cancel()
// ctx, cancel := context.WithCancel(ctx)
// defer cancel()

sub, err := e.Topic.Subscribe()
if err != nil {
Expand Down

0 comments on commit 2706d46

Please sign in to comment.