p2p: fix marshaling of NAT in TOML

This fixes an issue where a nat.Interface unmarshaled from the
TOML config file could not be re-marshaled to TOML correctly.
This commit is contained in:
Felix Lange 2025-02-16 23:43:38 +01:00
parent 68de26e346
commit 03f430a304

View file

@ -18,6 +18,7 @@ package p2p
import (
"crypto/ecdsa"
"encoding"
"fmt"
"github.com/ethereum/go-ethereum/common/mclock"
@ -135,6 +136,13 @@ type configNAT struct {
nat.Interface
}
func (w *configNAT) MarshalText() ([]byte, error) {
if tm, ok := w.Interface.(encoding.TextMarshaler); ok {
return tm.MarshalText()
}
return nil, fmt.Errorf("NAT specification %#v cannot be marshaled", w.Interface)
}
func (w *configNAT) UnmarshalText(input []byte) error {
n, err := nat.Parse(string(input))
if err != nil {