]> Cypherpunks.ru repositories - nncp.git/blob - src/cmd/nncp-cfgmin/main.go
Remove huge usage headers, -warranty exists anyway
[nncp.git] / src / cmd / nncp-cfgmin / main.go
1 /*
2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2023 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, version 3 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 // Stripped NNCP configuration file.
19 package main
20
21 import (
22         "flag"
23         "fmt"
24         "log"
25         "os"
26
27         "github.com/hjson/hjson-go"
28         "go.cypherpunks.ru/nncp/v8"
29 )
30
31 func usage() {
32         fmt.Fprint(os.Stderr, "nncp-cfgmin -- print stripped configuration\n\n")
33         fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0])
34         flag.PrintDefaults()
35 }
36
37 func main() {
38         var (
39                 cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
40                 version  = flag.Bool("version", false, "Print version information")
41                 warranty = flag.Bool("warranty", false, "Print warranty information")
42         )
43         log.SetFlags(log.Lshortfile)
44         flag.Usage = usage
45         flag.Parse()
46         if *warranty {
47                 fmt.Println(nncp.Warranty)
48                 return
49         }
50         if *version {
51                 fmt.Println(nncp.VersionGet())
52                 return
53         }
54
55         ctx, err := nncp.CtxFromCmdline(*cfgPath, "", "", false, false, false, false)
56         if err != nil {
57                 log.Fatalln("Error during initialization:", err)
58         }
59
60         cfg := nncp.CfgJSON{
61                 Spool: ctx.Spool,
62                 Log:   ctx.LogPath,
63                 Neigh: make(map[string]nncp.NodeJSON),
64         }
65         for _, node := range ctx.Neigh {
66                 var noisePub *string
67                 if node.NoisePub != nil {
68                         np := nncp.Base32Codec.EncodeToString(node.NoisePub[:])
69                         noisePub = &np
70                 }
71                 cfg.Neigh[node.Name] = nncp.NodeJSON{
72                         Id:       node.Id.String(),
73                         ExchPub:  nncp.Base32Codec.EncodeToString(node.ExchPub[:]),
74                         SignPub:  nncp.Base32Codec.EncodeToString(node.SignPub[:]),
75                         NoisePub: noisePub,
76                 }
77         }
78         raw, err := hjson.Marshal(&cfg)
79         if err != nil {
80                 panic(err)
81         }
82         fmt.Print(string(raw))
83 }