forked from forks/go-ethereum
p2p: fix marshaling of NAT in TOML (#31192)
This fixes an issue where a nat.Interface unmarshaled from the TOML config file could not be re-marshaled to TOML correctly. Fixes #31183
This commit is contained in:
parent
e5bc789185
commit
c113e3b5b1
1 changed files with 8 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ package p2p
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"encoding"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/mclock"
|
"github.com/ethereum/go-ethereum/common/mclock"
|
||||||
|
|
@ -135,6 +136,13 @@ type configNAT struct {
|
||||||
nat.Interface
|
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 {
|
func (w *configNAT) UnmarshalText(input []byte) error {
|
||||||
n, err := nat.Parse(string(input))
|
n, err := nat.Parse(string(input))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue