From d8bd26bfe405edcd6487babaa1e3a5c8aac222c4 Mon Sep 17 00:00:00 2001 From: sc0vu Date: Tue, 5 Dec 2023 16:18:52 +0800 Subject: [PATCH] core: patch plugin and server --- katzenmint/s11n/descriptor.go | 6 +++--- plugin/cmd/meson-plugin/main.go | 21 +++++++++------------ server/internal/packet/packet.go | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/katzenmint/s11n/descriptor.go b/katzenmint/s11n/descriptor.go index 8f3ef0f5..acc88532 100644 --- a/katzenmint/s11n/descriptor.go +++ b/katzenmint/s11n/descriptor.go @@ -36,8 +36,8 @@ const ( var ( // CertificateExpiration is the time a descriptor certificate will be valid for. - // 10 epoch by default - CertificateExpiration uint64 = 10 + // 600 epoch by default + CertificateExpiration uint64 = 600 ) type nodeDescriptor struct { @@ -93,7 +93,7 @@ func ParseDescriptor(b []byte, epochNow uint64) (*pki.MixDescriptor, error) { if err != nil { return nil, err } - if epochNow > signedCert.Expiration { + if (epochNow + 1) > signedCert.Expiration { return nil, cert.ErrCertificateExpired } payload, err := cert.GetCertified(b) diff --git a/plugin/cmd/meson-plugin/main.go b/plugin/cmd/meson-plugin/main.go index 6870b661..1ecf3cae 100644 --- a/plugin/cmd/meson-plugin/main.go +++ b/plugin/cmd/meson-plugin/main.go @@ -135,11 +135,11 @@ func main() { // Ensure that the log directory exists. s, err := os.Stat(logDir) if os.IsNotExist(err) { - fmt.Printf("Log directory '%s' doesn't exist.", logDir) + log.Errorf("Log directory '%s' doesn't exist.", logDir) os.Exit(1) } if !s.IsDir() { - fmt.Println("Log directory must actually be a directory.") + log.Error("Log directory must actually be a directory.") os.Exit(1) } @@ -147,8 +147,7 @@ func main() { logFile := path.Join(logDir, fmt.Sprintf("currency.%d.log", os.Getpid())) f, err := os.Create(logFile) if err != nil { - log.Errorf("Failed to create log file '%v: %v\n'", logFile, err) - log.Error("Exiting") + log.Errorf("Failed to create log file '%v: %v\n'Exiting\n", logFile, err) os.Exit(-1) } logBackend := setupLoggerBackend(level, f) @@ -161,16 +160,14 @@ func main() { // Load config file. cfg, err := config.LoadFile(*cfgFile) if err != nil { - log.Errorf("Failed to load config file '%v: %v\n'", *cfgFile, err) - log.Error("Exiting") + log.Errorf("Failed to load config file '%v: %v\n'Exiting\n", *cfgFile, err) os.Exit(-1) } // Start service. currency, err := proxy.New(cfg) if err != nil { - log.Errorf("Failed to load proxy config: %v\n", err) - log.Error("Exiting") + log.Errorf("Failed to load proxy config: %v\nExiting\n", err) os.Exit(-1) } _requestHandler := func(response http.ResponseWriter, request *http.Request) { @@ -181,10 +178,10 @@ func main() { } server := http.Server{} socketFile := fmt.Sprintf("/tmp/%d.currency.socket", os.Getpid()) + defer os.Remove(socketFile) unixListener, err := net.Listen("unix", socketFile) if err != nil { - log.Errorf("Failed to start server: %v\n", err) - log.Error("Exiting") + log.Errorf("Failed to start server: %v\nExiting\n", err) os.Exit(-1) } http.HandleFunc("/request", _requestHandler) @@ -192,7 +189,7 @@ func main() { fmt.Printf("%s\n", socketFile) err = server.Serve(unixListener) if err != nil { - fmt.Println(err) + log.Errorf("Failed to start server: %v\nExiting\n", err) + os.Exit(-1) } - os.Remove(socketFile) } diff --git a/server/internal/packet/packet.go b/server/internal/packet/packet.go index 3849eef1..2dd53cf1 100644 --- a/server/internal/packet/packet.go +++ b/server/internal/packet/packet.go @@ -186,7 +186,7 @@ func (pkt *Packet) copyToRaw(b []byte) error { func (pkt *Packet) disposeRaw() { if len(pkt.Raw) == constants.PacketLength { utils.ExplicitBzero(pkt.Raw) - rawPacketPool.Put(&pkt.Raw) // nolint: megacheck + rawPacketPool.Put(pkt.Raw) // nolint: megacheck } pkt.Raw = nil }