]> Cypherpunks.ru repositories - nncp.git/commitdiff
Configure sendmail command per node
authorSergey Matveev <stargrave@stargrave.org>
Sun, 8 Jan 2017 09:23:48 +0000 (12:23 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 8 Jan 2017 09:23:48 +0000 (12:23 +0300)
src/cypherpunks.ru/nncp/cfg.go
src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go
src/cypherpunks.ru/nncp/ctx.go
src/cypherpunks.ru/nncp/node.go
src/cypherpunks.ru/nncp/toss.go
src/cypherpunks.ru/nncp/toss_test.go

index 9092be08c83fd48fbe6ec55277f2ff9fa121c6ca..661a6b6f8b31c6ec6d54e262e566307435ba6b4c 100644 (file)
@@ -36,6 +36,7 @@ type NodeYAML struct {
        ExchPub  string
        SignPub  string
        NoisePub string
+       Sendmail []string
        Incoming *string  `incoming,omitempty`
        Freq     *string  `freq,omitempty`
        Via      []string `via,omitempty`
@@ -67,10 +68,9 @@ type CfgYAML struct {
        Self  NodeOurYAML
        Neigh map[string]NodeYAML
 
-       Spool    string
-       Log      string
-       Sendmail []string
-       Notify   *NotifyYAML `notify,omitempty`
+       Spool  string
+       Log    string
+       Notify *NotifyYAML `notify,omitempty`
 }
 
 func NewNode(name string, yml NodeYAML) (*Node, error) {
@@ -127,6 +127,7 @@ func NewNode(name string, yml NodeYAML) (*Node, error) {
                ExchPub:  new([32]byte),
                SignPub:  ed25519.PublicKey(signPub),
                NoisePub: new([32]byte),
+               Sendmail: yml.Sendmail,
                Incoming: incoming,
                Freq:     freq,
                Addrs:    yml.Addrs,
@@ -242,12 +243,11 @@ func CfgParse(data []byte) (*Ctx, error) {
                return nil, errors.New("Log path must be absolute")
        }
        ctx := Ctx{
-               Spool:    spoolPath,
-               LogPath:  logPath,
-               Self:     self,
-               Neigh:    make(map[NodeId]*Node, len(cfgYAML.Neigh)),
-               Alias:    make(map[string]*NodeId),
-               Sendmail: cfgYAML.Sendmail,
+               Spool:   spoolPath,
+               LogPath: logPath,
+               Self:    self,
+               Neigh:   make(map[NodeId]*Node, len(cfgYAML.Neigh)),
+               Alias:   make(map[string]*NodeId),
        }
        if cfgYAML.Notify != nil {
                if cfgYAML.Notify.File != nil {
index eb12d1dd27201fad96e5baea1dac467a524b1088..ada5af0a4cf3457b5d8335cafd16691b4d2ea7ce 100644 (file)
@@ -71,14 +71,14 @@ func main() {
                                ExchPub:  nncp.ToBase32(nodeOur.ExchPub[:]),
                                SignPub:  nncp.ToBase32(nodeOur.SignPub[:]),
                                NoisePub: nncp.ToBase32(nodeOur.NoisePub[:]),
+                               Sendmail: []string{nncp.DefaultSendmailPath},
                                Incoming: &incoming,
                                Freq:     &freq,
                                Addrs:    map[string]string{"main": "localhost:5400"},
                        },
                },
-               Spool:    "/path/to/spool",
-               Log:      "/path/to/log.file",
-               Sendmail: []string{nncp.DefaultSendmailPath},
+               Spool: "/path/to/spool",
+               Log:   "/path/to/log.file",
                Notify: &nncp.NotifyYAML{
                        File: &nncp.FromToYAML{
                                From: "nncp@localhost",
index 1122f455c93449501b3dc25b390fdac313a239ed..340791139b491b2ac36c446e90c16e0f92597db7 100644 (file)
@@ -29,9 +29,7 @@ type Ctx struct {
        Neigh map[NodeId]*Node
        Alias map[string]*NodeId
 
-       Spool    string
-       Sendmail []string
-
+       Spool      string
        LogPath    string
        Debug      bool
        NotifyFile *FromToYAML
index 05c41fda40646b48172ab45d5c9a0a9f208d253d..8b3a012732cdea009e647511faa0921eaa2caf2d 100644 (file)
@@ -40,6 +40,7 @@ type Node struct {
        ExchPub  *[32]byte
        SignPub  ed25519.PublicKey
        NoisePub *[32]byte
+       Sendmail []string
        Incoming *string
        Freq     *string
        Via      []*NodeId
index 7434c1af551bef0338fdaee2bfb936e274e7f03e..c426987a747c54a754b132a44ac57e66753eedf6 100644 (file)
@@ -130,10 +130,11 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8) {
                        if err != nil {
                                log.Fatalln(err)
                        }
+                       sendmail := ctx.Neigh[*job.PktEnc.Sender].Sendmail
                        cmd := exec.Command(
-                               ctx.Sendmail[0],
+                               sendmail[0],
                                append(
-                                       ctx.Sendmail[1:len(ctx.Sendmail)],
+                                       sendmail[1:len(sendmail)],
                                        strings.Split(recipients, " ")...,
                                )...,
                        )
@@ -196,13 +197,11 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8) {
                        if err = os.Remove(job.Fd.Name()); err != nil {
                                ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "remove")
                        }
+                       sendmail := ctx.Neigh[*ctx.Self.Id].Sendmail
                        if ctx.NotifyFile != nil {
                                cmd := exec.Command(
-                                       ctx.Sendmail[0],
-                                       append(
-                                               ctx.Sendmail[1:len(ctx.Sendmail)],
-                                               ctx.NotifyFile.To,
-                                       )...,
+                                       sendmail[0],
+                                       append(sendmail[1:len(sendmail)], ctx.NotifyFile.To)...,
                                )
                                cmd.Stdin = newNotification(ctx.NotifyFile, fmt.Sprintf(
                                        "File from %s: %s (%s)",
@@ -238,12 +237,10 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8) {
                                ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "remove")
                        }
                        if ctx.NotifyFreq != nil {
+                               sendmail := ctx.Neigh[*ctx.Self.Id].Sendmail
                                cmd := exec.Command(
-                                       ctx.Sendmail[0],
-                                       append(
-                                               ctx.Sendmail[1:len(ctx.Sendmail)],
-                                               ctx.NotifyFreq.To,
-                                       )...,
+                                       sendmail[0],
+                                       append(sendmail[1:len(sendmail)], ctx.NotifyFreq.To)...,
                                )
                                cmd.Stdin = newNotification(ctx.NotifyFreq, fmt.Sprintf(
                                        "Freq from %s: %s",
index 3f948038f7358b9428edd4851ec96471fbf0b5f9..001a25b5618191230e322f8f85ec6b4795ec929a 100644 (file)
@@ -107,12 +107,12 @@ func TestTossEmail(t *testing.T) {
                        if len(dirFiles(rxPath)) == 0 {
                                return false
                        }
-                       ctx.Sendmail = []string{"/bin/sh", "-c", "false"}
+                       ctx.Neigh[*nodeOur.Id].Sendmail = []string{"/bin/sh", "-c", "false"}
                        ctx.Toss(ctx.Self.Id, DefaultNiceMail)
                        if len(dirFiles(rxPath)) == 0 {
                                return false
                        }
-                       ctx.Sendmail = []string{
+                       ctx.Neigh[*nodeOur.Id].Sendmail = []string{
                                "/bin/sh", "-c",
                                fmt.Sprintf("cat >> %s", filepath.Join(spool, "mbox")),
                        }