User-facing command lines

This commit is contained in:
Neil Alexander
2021-07-09 18:42:52 +01:00
parent eb8b2d5822
commit 4b2f955f69
3 changed files with 35 additions and 15 deletions

View File

@@ -33,15 +33,17 @@ Create a mailbox and set your password. Your Yggmail database will automatically
yggmail -password
```
Start Yggmail, using the database in your working directory:
Start Yggmail, using the database in your working directory, with either multicast enabled, an [Yggdrasil static peer](https://publicpeers.neilalexander.dev/) specified or both:
```
yggmail -smtp=localhost:1025 -imap=localhost:1026
yggmail -multicast
yggmail -peer=tls://...
yggmail -multicast -peer=tls://...
```
Connect your mail client to Yggmail. In the above example:
* SMTP is listening on `localhost` port 1025, password authentication, no SSL/TLS
* IMAP is listening on `localhost` port 1026, password authentication, no SSL/TLS
* IMAP is listening on `localhost` port 1143, password authentication, no SSL/TLS
Then try sending a mail to another Yggmail user!
@@ -50,6 +52,7 @@ Then try sending a mail to another Yggmail user!
The following command line switches are supported by the `yggmail` binary:
* `-peer=tls://...` or `-peer=tcp://...` — connect to a specific Yggdrasil node, like one of the [Public Peers](https://publicpeers.neilalexander.dev/);
* `-multicast` - enable multicast peer discovery for Yggdrasil nodes on your LAN
* `-database=/path/to/yggmail.db` — use a specific database file;
* `-smtp=listenaddr:port` — listen for SMTP on a specific address/port
* `-imap=listenaddr:port` — listen for IMAP on a specific address/port;

View File

@@ -27,16 +27,26 @@ import (
var database = flag.String("database", "yggmail.db", "SQLite database file")
var smtpaddr = flag.String("smtp", "localhost:1025", "SMTP listen address")
var imapaddr = flag.String("imap", "localhost:1026", "IMAP listen address")
var peeraddr = flag.String("peer", "", "Yggdrasil static peer")
var imapaddr = flag.String("imap", "localhost:1143", "IMAP listen address")
var peeraddr = flag.String("peer", "", "Connect to a specific Yggdrasil static peer")
var multicast = flag.Bool("multicast", false, "Connect to Yggdrasil peers on your LAN")
var password = flag.Bool("password", false, "Set a new IMAP/SMTP password")
func main() {
flag.Parse()
rawlog := log.New(os.Stdout, "", 0)
log := log.New(rawlog.Writer(), "[ \033[32mYggmail\033[0m ] ", 0)
flag.Parse()
if flag.NFlag() == 0 {
fmt.Println("Yggmail must be started with either an Yggdrasil peer")
fmt.Println("specified, multicast enabled, or both.")
fmt.Println()
fmt.Println("Available options:")
fmt.Println()
flag.PrintDefaults()
os.Exit(0)
}
storage, err := sqlite3.NewSQLite3StorageStorage(*database)
if err != nil {
panic(err)
@@ -95,6 +105,10 @@ func main() {
log.Println("Password for IMAP and SMTP has been updated!")
os.Exit(0)
case (multicast == nil || !*multicast) && (peeraddr == nil || *peeraddr == ""):
log.Printf("You must specify either -peer, -multicast or both!")
os.Exit(0)
}
cfg := &config.Config{
@@ -104,7 +118,7 @@ func main() {
wg := &sync.WaitGroup{}
wg.Add(2)
transport, err := transport.NewYggdrasilTransport(rawlog, sk, pk, *peeraddr)
transport, err := transport.NewYggdrasilTransport(rawlog, sk, pk, *peeraddr, *multicast)
if err != nil {
panic(err)
}

View File

@@ -19,7 +19,7 @@ type YggdrasilTransport struct {
Sessions *utp.Socket
}
func NewYggdrasilTransport(log *log.Logger, sk ed25519.PrivateKey, pk ed25519.PublicKey, peer string) (*YggdrasilTransport, error) {
func NewYggdrasilTransport(log *log.Logger, sk ed25519.PrivateKey, pk ed25519.PublicKey, peer string, mcast bool) (*YggdrasilTransport, error) {
config := &config.NodeConfig{
PublicKey: hex.EncodeToString(pk),
PrivateKey: hex.EncodeToString(sk),
@@ -33,6 +33,7 @@ func NewYggdrasilTransport(log *log.Logger, sk ed25519.PrivateKey, pk ed25519.Pu
NodeInfo: map[string]interface{}{
"name": "Yggmail",
},
NodeInfoPrivacy: true,
}
if peer != "" {
config.Peers = append(config.Peers, peer)
@@ -45,12 +46,14 @@ func NewYggdrasilTransport(log *log.Logger, sk ed25519.PrivateKey, pk ed25519.Pu
if err := core.Start(config, glog); err != nil {
return nil, fmt.Errorf("core.Start: %w", err)
}
multicast := &multicast.Multicast{}
if err := multicast.Init(core, config, glog, nil); err != nil {
return nil, fmt.Errorf("multicast.Init: %w", err)
}
if err := multicast.Start(); err != nil {
return nil, fmt.Errorf("multicast.Start: %w", err)
if mcast {
multicast := &multicast.Multicast{}
if err := multicast.Init(core, config, glog, nil); err != nil {
return nil, fmt.Errorf("multicast.Init: %w", err)
}
if err := multicast.Start(); err != nil {
return nil, fmt.Errorf("multicast.Start: %w", err)
}
}
us, err := utp.NewSocketFromPacketConnNoClose(core)
if err != nil {