]> Cypherpunks.ru repositories - nncp.git/blob - src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go
a8e73e6591eeb104a34348f2a913627cfd230ff3
[nncp.git] / src / cypherpunks.ru / nncp / cmd / nncp-newnode / main.go
1 /*
2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 // Generate new NNCP node keys
20 package main
21
22 import (
23         "flag"
24         "fmt"
25         "os"
26
27         "cypherpunks.ru/nncp"
28         "gopkg.in/yaml.v2"
29 )
30
31 func usage() {
32         fmt.Fprintf(os.Stderr, nncp.UsageHeader())
33         fmt.Fprintln(os.Stderr, "nncp-newnode -- generate new node keys\nOptions:")
34         flag.PrintDefaults()
35 }
36
37 func main() {
38         var (
39                 version  = flag.Bool("version", false, "Print version information")
40                 warranty = flag.Bool("warranty", false, "Print warranty information")
41         )
42         flag.Usage = usage
43         flag.Parse()
44         if *warranty {
45                 fmt.Println(nncp.Warranty)
46                 return
47         }
48         if *version {
49                 fmt.Println(nncp.VersionGet())
50                 return
51         }
52         nodeOur, err := nncp.NewNodeGenerate()
53         if err != nil {
54                 panic(err)
55         }
56         incoming := "/path/to/upload/dir, omit it to forbid uploading"
57         freq := "/path/to/freq/able/dir, omit to forbid freqing"
58         noisePub := nncp.ToBase32(nodeOur.NoisePub[:])
59         cfg := nncp.CfgYAML{
60                 Self: nncp.NodeOurYAML{
61                         Id:       nodeOur.Id.String(),
62                         ExchPub:  nncp.ToBase32(nodeOur.ExchPub[:]),
63                         ExchPrv:  nncp.ToBase32(nodeOur.ExchPrv[:]),
64                         SignPub:  nncp.ToBase32(nodeOur.SignPub[:]),
65                         SignPrv:  nncp.ToBase32(nodeOur.SignPrv[:]),
66                         NoisePub: nncp.ToBase32(nodeOur.NoisePub[:]),
67                         NoisePrv: nncp.ToBase32(nodeOur.NoisePrv[:]),
68                 },
69                 Neigh: map[string]nncp.NodeYAML{
70                         "self": nncp.NodeYAML{
71                                 Id:       nodeOur.Id.String(),
72                                 ExchPub:  nncp.ToBase32(nodeOur.ExchPub[:]),
73                                 SignPub:  nncp.ToBase32(nodeOur.SignPub[:]),
74                                 NoisePub: &noisePub,
75                                 Sendmail: []string{nncp.DefaultSendmailPath},
76                                 Incoming: &incoming,
77                                 Freq:     &freq,
78                                 Addrs:    map[string]string{"main": "localhost:5400"},
79                         },
80                 },
81                 Spool: "/path/to/spool",
82                 Log:   "/path/to/log.file",
83                 Notify: &nncp.NotifyYAML{
84                         File: &nncp.FromToYAML{
85                                 From: "nncp@localhost",
86                                 To:   "root@localhost, delete section to disable notifies",
87                         },
88                         Freq: &nncp.FromToYAML{
89                                 From: "nncp@localhost",
90                                 To:   "root@localhost, delete section to disable notifies",
91                         },
92                 },
93         }
94         raw, err := yaml.Marshal(&cfg)
95         if err != nil {
96                 panic(err)
97         }
98         fmt.Print(string(raw))
99 }