Skip to content

Commit 3ce1bef

Browse files
committed
restore compression headers
1 parent bb4eb38 commit 3ce1bef

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

network/wsNetwork.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ func (wn *WebsocketNetwork) ServeHTTP(response http.ResponseWriter, request *htt
10581058
responseHeader.Set(ProtocolVersionHeader, matchingVersion)
10591059
responseHeader.Set(GenesisHeader, wn.GenesisID)
10601060
// set the features we support, for example
1061-
// responseHeader.Set(PeerFeaturesHeader, "ppzstd")
1061+
responseHeader.Set(PeerFeaturesHeader, PeerFeatureProposalCompression)
10621062
var challenge string
10631063
if wn.prioScheme != nil {
10641064
challenge = wn.prioScheme.NewPrioChallenge()
@@ -1387,7 +1387,7 @@ func (wn *WebsocketNetwork) getPeersChangeCounter() int32 {
13871387
}
13881388

13891389
// preparePeerData prepares batches of data for sending.
1390-
// It performs optional zstd compression for proposal massages
1390+
// It performs zstd compression for proposal massages if they this is a prio request and has proposal.
13911391
func (wn *msgBroadcaster) preparePeerData(request broadcastRequest, prio bool) ([][]byte, []crypto.Digest) {
13921392
// determine if there is a payload proposal and peers supporting compressed payloads
13931393
shouldCompress := false
@@ -1954,6 +1954,10 @@ const UserAgentHeader = "User-Agent"
19541954
// PeerFeaturesHeader is the HTTP header listing features
19551955
const PeerFeaturesHeader = "X-Algorand-Peer-Features"
19561956

1957+
// PeerFeatureProposalCompression is a value for PeerFeaturesHeader indicating peer
1958+
// supports proposal payload compression with zstd
1959+
const PeerFeatureProposalCompression = "ppzstd"
1960+
19571961
var websocketsScheme = map[string]string{"http": "ws", "https": "wss"}
19581962

19591963
var errBadAddr = errors.New("bad address")
@@ -2075,8 +2079,8 @@ func (wn *WebsocketNetwork) tryConnect(netAddr, gossipAddr string) {
20752079

20762080
// for backward compatibility, include the ProtocolVersion header as well.
20772081
requestHeader.Set(ProtocolVersionHeader, wn.protocolVersion)
2078-
// set the features header (comma-separated list), for example
2079-
requestHeader.Set(PeerFeaturesHeader, "ppzstd")
2082+
// set the features header (comma-separated list)
2083+
requestHeader.Set(PeerFeaturesHeader, PeerFeatureProposalCompression)
20802084
SetUserAgentHeader(requestHeader)
20812085
myInstanceName := wn.log.GetInstanceName()
20822086
requestHeader.Set(InstanceNameHeader, myInstanceName)

network/wsNetwork_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ func TestWebsocketProposalPayloadCompression(t *testing.T) {
434434

435435
// old node + new node
436436
{[]string{"2.1"}, "2.1", []string{"2.2", "2.1"}, "2.2"},
437+
{[]string{"2.2", "2.1"}, "2.1", []string{"2.2"}, "2.2"},
437438

438439
// combinations
439440
{[]string{"2.2", "2.1"}, "2.1", []string{"2.2", "2.1"}, "2.1"},

network/wsPeer.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,10 @@ func (wp *wsPeer) OnClose(f func()) {
11761176
//msgp:ignore peerFeatureFlag
11771177
type peerFeatureFlag int
11781178

1179+
const (
1180+
pfCompressedProposal peerFeatureFlag = 1 << iota
1181+
)
1182+
11791183
// versionPeerFeatures defines protocol version when peer features were introduced
11801184
const versionPeerFeatures = "2.2"
11811185

@@ -1214,11 +1218,10 @@ func decodePeerFeatures(version string, announcedFeatures string) peerFeatureFla
12141218
var features peerFeatureFlag
12151219
parts := strings.Split(announcedFeatures, ",")
12161220
for _, part := range parts {
1217-
// check features here, for example
1218-
_ = strings.TrimSpace(part)
1219-
// if part == "ppzstd" {
1220-
// features |= pfCompressedProposal
1221-
// }
1221+
part = strings.TrimSpace(part)
1222+
if part == PeerFeatureProposalCompression {
1223+
features |= pfCompressedProposal
1224+
}
12221225
}
12231226
return features
12241227
}

network/wsPeer_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,14 @@ func TestVersionToFeature(t *testing.T) {
159159
{"1.2.3", "", peerFeatureFlag(0)},
160160
{"a.b", "", peerFeatureFlag(0)},
161161
{"2.1", "", peerFeatureFlag(0)},
162-
{"2.1", "", peerFeatureFlag(0)},
162+
{"2.1", PeerFeatureProposalCompression, peerFeatureFlag(0)},
163163
{"2.2", "", peerFeatureFlag(0)},
164164
{"2.2", "test", peerFeatureFlag(0)},
165165
{"2.2", strings.Join([]string{"a", "b"}, ","), peerFeatureFlag(0)},
166+
{"2.2", PeerFeatureProposalCompression, pfCompressedProposal},
167+
{"2.2", strings.Join([]string{PeerFeatureProposalCompression, "test"}, ","), pfCompressedProposal},
168+
{"2.2", strings.Join([]string{PeerFeatureProposalCompression, "test"}, ", "), pfCompressedProposal},
169+
{"2.3", PeerFeatureProposalCompression, pfCompressedProposal},
166170
}
167171
for i, test := range tests {
168172
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {

0 commit comments

Comments
 (0)