-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
114 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/make -ef | ||
|
||
|
||
NAME = go-ma-home | ||
NAME = go-ma-pong | ||
PREFIX ?= /usr/local | ||
|
||
default: clean $(NAME) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Pong! | ||
|
||
This is is a silly, but really useful actor, which only sends back a pong! | ||
upon receiving of a 間 message. | ||
|
||
So you can leave it on, just so that you always have something | ||
to reply to, when testing. |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module go-ma-home | ||
module go-ma-pong | ||
|
||
go 1.21.6 | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package ui | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/bahner/go-ma-actor/p2p/topic" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// Handle incoming messages. NB! This must be cancelled, | ||
// when topic (localtion/home) changes. | ||
func (ui *ChatUI) handleTopicEvents() { | ||
|
||
ctx := context.Background() | ||
|
||
t, err := topic.GetOrCreate(ui.e.DID) | ||
envelopes := t.SubscribeEnvelopes(ctx) | ||
if err != nil { | ||
log.Debugf("topic creation error: %s", err) | ||
return | ||
} | ||
|
||
for { | ||
log.Debugf("Waiting for messages...") | ||
select { | ||
case e, ok := <-envelopes: | ||
if !ok { | ||
log.Debug("Envelope channel closed, exiting...") | ||
return | ||
} | ||
log.Debugf("Received envelope: %v", e) | ||
|
||
// Process the envelope and send a pong response | ||
m, err := e.Open(ui.a.Entity.Keyset.EncryptionKey.PrivKey[:]) | ||
if err != nil { | ||
log.Errorf("Error opening envelope: %v\n", err) | ||
continue | ||
} | ||
|
||
log.Debugf("Received message: %v\n", string(m.Content)) | ||
|
||
// Check if the message is from self to prevent pong loop | ||
if m.From != ui.a.Entity.DID.String() { | ||
log.Debugf("Received message from %s", m.From) | ||
ui.displayChatMessage(m) | ||
} else { | ||
log.Debugf("Received message from self, ignoring...") | ||
} | ||
|
||
case <-ctx.Done(): | ||
log.Debug("Context done, exiting...") | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters