@@ -137,36 +137,49 @@ func (mq *msgQueue) runQueue(ctx context.Context) {
137
137
for {
138
138
select {
139
139
case <- mq .work : // there is work to be done
140
-
141
- err := mq .network .ConnectTo (ctx , mq .p )
142
- if err != nil {
143
- log .Noticef ("cant connect to peer %s: %s" , mq .p , err )
144
- // TODO: cant connect, what now?
145
- continue
146
- }
147
-
148
- // grab outgoing message
149
- mq .outlk .Lock ()
150
- wlm := mq .out
151
- if wlm == nil || wlm .Empty () {
152
- mq .outlk .Unlock ()
153
- continue
154
- }
155
- mq .out = nil
156
- mq .outlk .Unlock ()
157
-
158
- // send wantlist updates
159
- err = mq .network .SendMessage (ctx , mq .p , wlm )
160
- if err != nil {
161
- log .Noticef ("bitswap send error: %s" , err )
162
- // TODO: what do we do if this fails?
163
- }
140
+ mq .doWork (ctx )
164
141
case <- mq .done :
165
142
return
166
143
}
167
144
}
168
145
}
169
146
147
+ func (mq * msgQueue ) doWork (ctx context.Context ) {
148
+ // allow ten minutes for connections
149
+ // this includes looking them up in the dht
150
+ // dialing them, and handshaking
151
+ conctx , cancel := context .WithTimeout (ctx , time .Minute * 10 )
152
+ defer cancel ()
153
+
154
+ err := mq .network .ConnectTo (conctx , mq .p )
155
+ if err != nil {
156
+ log .Noticef ("cant connect to peer %s: %s" , mq .p , err )
157
+ // TODO: cant connect, what now?
158
+ return
159
+ }
160
+
161
+ // grab outgoing message
162
+ mq .outlk .Lock ()
163
+ wlm := mq .out
164
+ if wlm == nil || wlm .Empty () {
165
+ mq .outlk .Unlock ()
166
+ return
167
+ }
168
+ mq .out = nil
169
+ mq .outlk .Unlock ()
170
+
171
+ sendctx , cancel := context .WithTimeout (ctx , time .Minute * 5 )
172
+ defer cancel ()
173
+
174
+ // send wantlist updates
175
+ err = mq .network .SendMessage (sendctx , mq .p , wlm )
176
+ if err != nil {
177
+ log .Noticef ("bitswap send error: %s" , err )
178
+ // TODO: what do we do if this fails?
179
+ return
180
+ }
181
+ }
182
+
170
183
func (pm * WantManager ) Connected (p peer.ID ) {
171
184
pm .connect <- p
172
185
}
0 commit comments