use constants for stream reuse heuristics
License: MIT Signed-off-by: Jeromy <why@ipfs.io>
Jeromy committed
Jun 7, 2016 at 01:27 UTC
dc4c21ef0203d81af815a4745c63bbb28707c6f5
1 file changed
+7
-2
routing/dht/dht_net.go
+7
-2
@@ -151,6 +151,11 @@ func (ms *messageSender) prep() error {
151
return nil
152
}
153
154
+// streamReuseTries is the number of times we will try to reuse a stream to a
155
+// given peer before giving up and reverting to the old one-message-per-stream
156
+// behaviour.
157
+const streamReuseTries = 3
158
+
159
func (ms *messageSender) SendMessage(ctx context.Context, pmes *pb.Message) error {
160
ms.lk.Lock()
161
defer ms.lk.Unlock()
@@ -162,7 +167,7 @@ func (ms *messageSender) SendMessage(ctx context.Context, pmes *pb.Message) erro
167
return err
168
}
169
165
- if ms.singleMes > 3 {
170
+ if ms.singleMes > streamReuseTries {
171
ms.s.Close()
172
ms.s = nil
173
}
@@ -215,7 +220,7 @@ func (ms *messageSender) SendRequest(ctx context.Context, pmes *pb.Message) (*pb
220
return nil, err
221
}
222
218
- if ms.singleMes > 3 {
223
+ if ms.singleMes > streamReuseTries {
224
ms.s.Close()
225
ms.s = nil
226
}