Skip to content

Commit

Permalink
Match go-ma envelope refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Nov 25, 2023
1 parent 44398eb commit a8302d3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ go-space-thumb*
go-ma-actor
spacetar
go-ma-actor.log
go-ma-actor
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ifneq (,$(wildcard ./.env))
export
endif

default: clean tidy $(NAME)
default: clean tidy $(NAME) install

init: go.mod tidy

Expand Down Expand Up @@ -43,8 +43,8 @@ image:
--build-arg "BUILD_IMAGE=$(BUILD_IMAGE)" \
.

install:
install -Dm755 $(NAME) $(DESTDIR)$(PREFIX)/bin/$(NAME)
install: $(NAME)
sudo install -Dm755 $(NAME) $(DESTDIR)$(PREFIX)/bin/$(NAME)

run: clean $(NAME)
./$(NAME)
Expand Down
2 changes: 1 addition & 1 deletion actor/envelopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (a *Actor) receiveEnvelopes() (*msg.Message, error) {
return nil, fmt.Errorf("failed to receive message from inbox: %w", err)
}

message, err := e.Open(a.Entity.Keyset.EncryptionKey.PrivKey)
message, err := msg.OpenEnvelope(e, a.Entity.Keyset.EncryptionKey.PrivKey[:])
if err != nil {
return nil, fmt.Errorf("failed to open envelope: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bahner/go-ma-actor
go 1.21

require (
github.com/bahner/go-ma v0.0.3-0.20231124201448-9164f10e4407
github.com/bahner/go-ma v0.0.3
github.com/c-bata/go-prompt v0.2.6
github.com/gdamore/tcell/v2 v2.6.0
github.com/libp2p/go-libp2p v0.32.1
Expand Down
14 changes: 2 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/bahner/go-ma v0.0.3-0.20231123054724-841ea2c4f791 h1:Ojgj190OD3tXz8YuSoWIa/PEdNeePwlE4SO0vETSDiM=
github.com/bahner/go-ma v0.0.3-0.20231123054724-841ea2c4f791/go.mod h1:j7zxx7dS8Vx37Bpr31XO3II6lvNTWp7pC7MDEIZU3xM=
github.com/bahner/go-ma v0.0.3-0.20231124181059-35cf14fae796 h1:K+baRKgOcHMTIMXORP75kbi8EHxAq+Kz6yGcvKAdNSs=
github.com/bahner/go-ma v0.0.3-0.20231124181059-35cf14fae796/go.mod h1:4M7gjLfsPwWOz5geqt27TEvt7fKnXuc90gnt8QP3Lbw=
github.com/bahner/go-ma v0.0.3-0.20231124181451-a9d2d123dcad h1:wOgrUYBCaClYIvky/ubrLYC9fixBjkb6MaxihtYonWQ=
github.com/bahner/go-ma v0.0.3-0.20231124181451-a9d2d123dcad/go.mod h1:j7zxx7dS8Vx37Bpr31XO3II6lvNTWp7pC7MDEIZU3xM=
github.com/bahner/go-ma v0.0.3-0.20231124193112-665587548cd7 h1:l+H/tSBgmMXk/km+gq+4YP1lj2ej+Y/Q0xRSih9SmK8=
github.com/bahner/go-ma v0.0.3-0.20231124193112-665587548cd7/go.mod h1:j7zxx7dS8Vx37Bpr31XO3II6lvNTWp7pC7MDEIZU3xM=
github.com/bahner/go-ma v0.0.3-0.20231124200358-09ad5e480f22 h1:ZR3/CKqY49yMWg9q2/wZGzVL3DGLbSNePR1K7pRU1Wg=
github.com/bahner/go-ma v0.0.3-0.20231124200358-09ad5e480f22/go.mod h1:j7zxx7dS8Vx37Bpr31XO3II6lvNTWp7pC7MDEIZU3xM=
github.com/bahner/go-ma v0.0.3-0.20231124201448-9164f10e4407 h1:c5RRktFV2T80HAiqT64+dDv933M64VjxQ4Gnu7yD+p4=
github.com/bahner/go-ma v0.0.3-0.20231124201448-9164f10e4407/go.mod h1:j7zxx7dS8Vx37Bpr31XO3II6lvNTWp7pC7MDEIZU3xM=
github.com/bahner/go-ma v0.0.3 h1:5HQQvz0Gaj4fZzjzjxbiqZG0egPRUHEoVhArz9Bq4Iw=
github.com/bahner/go-ma v0.0.3/go.mod h1:l9ty9QbOZfRUtovECXES7a01Su7xBYIBphFak1TOjVs=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down
23 changes: 18 additions & 5 deletions ui/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/bahner/go-ma-actor/config"
"github.com/bahner/go-ma-actor/p2p/topic"
"github.com/bahner/go-ma/did"
"github.com/bahner/go-ma/msg"
log "github.com/sirupsen/logrus"
)
Expand All @@ -13,7 +14,8 @@ import (
// with the sender's nick highlighted in green.
// func (ui *ChatUI) displayChatMessage(cm *msg.Message) {
func (ui *ChatUI) displayChatMessage(cm *msg.Message) {
prompt := withColor("green", fmt.Sprintf("<%s>:", cm.From))
from := did.GetFragment(cm.From)
prompt := withColor("green", fmt.Sprintf("<%s>:", from))
fmt.Fprintf(ui.msgW, "%s %s\n", prompt, string(cm.Body))
}

Expand All @@ -24,7 +26,7 @@ func (ui *ChatUI) handleChatMessage(input string) error {
msgBytes := []byte(input)
log.Debugf("ui.a.Entity.DID.Fragment: %s", ui.a.Entity.DID.Fragment)
log.Debugf("ui.e.ID: %s", ui.e.DID)
msg, err := msg.New(ui.a.Entity.DID.Fragment, ui.e.DID, msgBytes, "text/plain")
msg, err := msg.New(ui.a.Entity.DID.String(), ui.e.DID, msgBytes, "text/plain")
if err != nil {
log.Debugf("message creation error: %s", err)
return fmt.Errorf("message creation error: %w", err)
Expand All @@ -36,19 +38,30 @@ func (ui *ChatUI) handleChatMessage(input string) error {
log.Debugf("message signing error: %s", err)
return fmt.Errorf("message signing error: %w", err)
}
err = msg.VerifySignature()
if err != nil {
log.Debugf("failed to verify my own message: %s", err)
return fmt.Errorf("message verification error: %w", err)
}
ui.displayChatMessage(msg)
topic, err := topic.GetOrCreate(ui.e.DID)
if err != nil {
log.Debugf("topic creation error: %s", err)
return fmt.Errorf("topic creation error: %w", err)
}

msgBytes, err = msg.Bytes()
e, err := msg.Enclose()
if err != nil {
return fmt.Errorf("envelope creation error: %w", err)
}

letter, err := e.MarshalToCBOR()
if err != nil {
log.Debugf("message serialization error: %s", err)
return fmt.Errorf("message serialization error: %w", err)
return fmt.Errorf("message serialization error: %s", err)
}
err = topic.Topic.Publish(ui.ctx, msgBytes)

err = topic.Topic.Publish(ui.ctx, letter)
if err != nil {
log.Debugf("message publishing error: %s", err)
return fmt.Errorf("message publishing error: %w", err)
Expand Down

0 comments on commit a8302d3

Please sign in to comment.