Skip to content

Commit c113e3b

Browse files
authored
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
1 parent e5bc789 commit c113e3b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

p2p/config.go

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package p2p
1818

1919
import (
2020
"crypto/ecdsa"
21+
"encoding"
2122
"fmt"
2223

2324
"github.com/ethereum/go-ethereum/common/mclock"
@@ -135,6 +136,13 @@ type configNAT struct {
135136
nat.Interface
136137
}
137138

139+
func (w *configNAT) MarshalText() ([]byte, error) {
140+
if tm, ok := w.Interface.(encoding.TextMarshaler); ok {
141+
return tm.MarshalText()
142+
}
143+
return nil, fmt.Errorf("NAT specification %#v cannot be marshaled", w.Interface)
144+
}
145+
138146
func (w *configNAT) UnmarshalText(input []byte) error {
139147
n, err := nat.Parse(string(input))
140148
if err != nil {

0 commit comments

Comments
 (0)