@@ -47,7 +47,7 @@ func constructDefaultHTTPRouters(cfg *config.Config) ([]*routinghelpers.Parallel
47
47
var routers []* routinghelpers.ParallelRouter
48
48
// Append HTTP routers for additional speed
49
49
for _ , endpoint := range defaultHTTPRouters {
50
- httpRouter , err := irouting .ConstructHTTPRouter (endpoint , cfg .Identity .PeerID , cfg .Addresses . Swarm , cfg .Identity .PrivKey )
50
+ httpRouter , err := irouting .ConstructHTTPRouter (endpoint , cfg .Identity .PeerID , httpAddrsFromConfig ( cfg .Addresses ) , cfg .Identity .PrivKey )
51
51
if err != nil {
52
52
return nil , err
53
53
}
@@ -123,7 +123,7 @@ func constructDHTRouting(mode dht.ModeOpt) RoutingOption {
123
123
}
124
124
125
125
// ConstructDelegatedRouting is used when Routing.Type = "custom"
126
- func ConstructDelegatedRouting (routers config.Routers , methods config.Methods , peerID string , addrs [] string , privKey string ) RoutingOption {
126
+ func ConstructDelegatedRouting (routers config.Routers , methods config.Methods , peerID string , addrs config. Addresses , privKey string ) RoutingOption {
127
127
return func (args RoutingOptionArgs ) (routing.Routing , error ) {
128
128
return irouting .Parse (routers , methods ,
129
129
& irouting.ExtraDHTParams {
@@ -135,7 +135,7 @@ func ConstructDelegatedRouting(routers config.Routers, methods config.Methods, p
135
135
},
136
136
& irouting.ExtraHTTPParams {
137
137
PeerID : peerID ,
138
- Addrs : addrs ,
138
+ Addrs : httpAddrsFromConfig ( addrs ) ,
139
139
PrivKeyB64 : privKey ,
140
140
})
141
141
}
@@ -151,3 +151,31 @@ var (
151
151
DHTServerOption = constructDHTRouting (dht .ModeServer )
152
152
NilRouterOption = constructNilRouting
153
153
)
154
+
155
+ // httpAddrsFromConfig creates a list of addresses from the provided configuration to be used by HTTP delegated routers.
156
+ func httpAddrsFromConfig (cfgAddrs config.Addresses ) []string {
157
+ // Swarm addrs are announced by default
158
+ addrs := cfgAddrs .Swarm
159
+ // if Announce addrs are specified - override Swarm
160
+ if len (cfgAddrs .Announce ) > 0 {
161
+ addrs = cfgAddrs .Announce
162
+ } else if len (cfgAddrs .NoAnnounce ) > 0 {
163
+ // if Announce adds are not specified - filter Swarm addrs with NoAnnounce list
164
+ maddrs := map [string ]struct {}{}
165
+ for _ , addr := range addrs {
166
+ maddrs [addr ] = struct {}{}
167
+ }
168
+ for _ , addr := range cfgAddrs .NoAnnounce {
169
+ delete (maddrs , addr )
170
+ }
171
+ addrs = make ([]string , 0 , len (maddrs ))
172
+ for k := range maddrs {
173
+ addrs = append (addrs , k )
174
+ }
175
+ }
176
+ // append AppendAnnounce addrs to the result list
177
+ if len (cfgAddrs .AppendAnnounce ) > 0 {
178
+ addrs = append (addrs , cfgAddrs .AppendAnnounce ... )
179
+ }
180
+ return addrs
181
+ }
0 commit comments