Go implementation of the DDM core service. The main entry point for embedded use is
github.com/waus/ddm-go/pkg/service.
Create a service with a local work directory, then use typed accounts and protocol addresses instead of passing raw strings through application code.
package main
import (
"context"
"time"
"github.com/waus/ddm-go/pkg/proto"
"github.com/waus/ddm-go/pkg/service"
)
func main() {
ctx := context.Background()
app, err := service.NewApp("./ddm-data")
if err != nil {
panic(err)
}
defer app.Close()
alice, err := app.CreateAccount(ctx, "alice")
if err != nil {
panic(err)
}
recipient, err := proto.ParseAddress("recipient-ddm-address")
if err != nil {
panic(err)
}
if _, err := app.SendTextMessage(ctx, *alice, recipient, "hello", 24*time.Hour); err != nil {
panic(err)
}
}Common service operations:
CreateAccount/CreateAccountWithPolicycreate local identities.ListAccountsreturns local accounts.SendTextMessageandSendMarkdownMessageenqueue outbound messages.ListMailboxMessagesreads inbox and outbox messages.StartP2PDaemonstarts the libp2p sync server.StartHTTPDaemonstarts the HTTP JSON sync API.AddSourceadds an upstream sync source:http(s)URL,file://SQLite URL, or libp2p multiaddr.
Run the terminal UI from this module:
go run ./cmd/tuiUseful startup flags:
-workdir <path>: directory for the local SQLite database, default..-log-file <path>: TUI log file, defaultddm.log.-http: start the HTTP JSON sync API server (metrics included).-http-addr <host:port>: HTTP listen address used with-http, default127.0.0.1:8080.-p2p-addr <multiaddr>: libp2p listen multiaddr, default/ip4/0.0.0.0/tcp/23708.-p2p-public-relay: enable the resource-limited public libp2p relay service.-upstreams <list>: comma-separated upstream sync sources.
Example:
go run ./cmd/tui \
-workdir ./ddm-data \
-http \
-http-addr 127.0.0.1:8080 \
-p2p-addr /ip4/0.0.0.0/tcp/23708Build the image from the Go module directory:
docker build -t ddm-go .Run the daemon with p2p exposed on all host interfaces and HTTP published only on host localhost:
docker run --rm \
-v ddm-go-data:/data \
-p 23708:23708 \
-p 23708:23708/udp \
-p 127.0.0.1:8080:8080 \
ddm-goThe image starts ddm-cli with:
ddm-cli -workdir /data -http -http-addr 0.0.0.0:8080 -p2p-addr /ip4/0.0.0.0/tcp/23708Override or append CLI flags by passing a custom command to docker run.
