@@ -130,21 +130,30 @@ async def _add_nat_portmap(self, upnp_dev: upnpclient.upnp.Device) -> str:
130
130
131
131
external_ip = upnp_dev .WANIPConn1 .GetExternalIPAddress ()['NewExternalIPAddress' ]
132
132
for protocol , description in [('TCP' , 'ethereum p2p' ), ('UDP' , 'ethereum discovery' )]:
133
- upnp_dev .WANIPConn1 .AddPortMapping (
134
- NewRemoteHost = external_ip ,
135
- NewExternalPort = self .port ,
136
- NewProtocol = protocol ,
137
- NewInternalPort = self .port ,
138
- NewInternalClient = internal_ip ,
139
- NewEnabled = '1' ,
140
- NewPortMappingDescription = description ,
141
- NewLeaseDuration = self ._nat_portmap_lifetime ,
142
- )
143
- self ._mapping = PortMapping (
144
- '%s:%d' % (internal_ip , self .port ),
145
- '%s:%d' % (external_ip , self .port ),
146
- )
147
- self .logger .info ("NAT port forwarding successfully set up: %r" , self ._mapping )
133
+ try :
134
+ upnp_dev .WANIPConn1 .AddPortMapping (
135
+ NewRemoteHost = external_ip ,
136
+ NewExternalPort = self .port ,
137
+ NewProtocol = protocol ,
138
+ NewInternalPort = self .port ,
139
+ NewInternalClient = internal_ip ,
140
+ NewEnabled = '1' ,
141
+ NewPortMappingDescription = description ,
142
+ NewLeaseDuration = self ._nat_portmap_lifetime ,
143
+ )
144
+ except upnpclient .soap .SOAPError as exc :
145
+ self .logger .warning (
146
+ "Failed to setup port mapping for %s/%s: %s" ,
147
+ protocol ,
148
+ description ,
149
+ exc
150
+ )
151
+ else :
152
+ self ._mapping = PortMapping (
153
+ '%s:%d' % (internal_ip , self .port ),
154
+ '%s:%d' % (external_ip , self .port ),
155
+ )
156
+ self .logger .info ("NAT port forwarding successfully set up: %r" , self ._mapping )
148
157
return external_ip
149
158
150
159
async def _discover_upnp_devices (self ) -> AsyncGenerator [upnpclient .upnp .Device , None ]:
0 commit comments