Переглянути джерело

fix blank IMs in BeAIM client

Mike 1 рік тому
батько
коміт
e393cc89d4
2 змінених файлів з 20 додано та 23 видалено
  1. 9 12
      foodgroup/icbm.go
  2. 11 11
      foodgroup/icbm_test.go

+ 9 - 12
foodgroup/icbm.go

@@ -122,18 +122,10 @@ func (s ICBMService) ChannelMsgToHost(ctx context.Context, sess *state.Session,
 	}
 
 	clientIM := wire.SNAC_0x04_0x07_ICBMChannelMsgToClient{
-		Cookie:      inBody.Cookie,
-		ChannelID:   inBody.ChannelID,
-		TLVUserInfo: sess.TLVUserInfo(),
-		TLVRestBlock: wire.TLVRestBlock{
-			TLVList: wire.TLVList{
-				{
-					// todo only add this TLV if the sender wants client events
-					Tag:   wire.ICBMTLVWantEvents,
-					Value: []byte{},
-				},
-			},
-		},
+		Cookie:       inBody.Cookie,
+		ChannelID:    inBody.ChannelID,
+		TLVUserInfo:  sess.TLVUserInfo(),
+		TLVRestBlock: wire.TLVRestBlock{},
 	}
 
 	for _, tlv := range inBody.TLVRestBlock.TLVList {
@@ -150,6 +142,11 @@ func (s ICBMService) ChannelMsgToHost(ctx context.Context, sess *state.Session,
 		clientIM.Append(tlv)
 	}
 
+	// todo I forget why I added this TLV here, but it should be added
+	//  conditionally. I moved it from the beginning of the TLV list to the end
+	//  since BeAIM assumes that the first TLV is 0x02.
+	clientIM.Append(wire.NewTLVBE(wire.ICBMTLVWantEvents, []byte{}))
+
 	s.messageRelayer.RelayToScreenName(ctx, recipSess.IdentScreenName(), wire.SNACMessage{
 		Frame: wire.SNACFrame{
 			FoodGroup: wire.ICBM,

+ 11 - 11
foodgroup/icbm_test.go

@@ -71,14 +71,14 @@ func TestICBMService_ChannelMsgToHost(t *testing.T) {
 									TLVUserInfo: newTestSession("sender-screen-name", sessOptWarning(10)).TLVUserInfo(),
 									TLVRestBlock: wire.TLVRestBlock{
 										TLVList: wire.TLVList{
-											{
-												Tag:   wire.ICBMTLVWantEvents,
-												Value: []byte{},
-											},
 											{
 												Tag:   wire.ICBMTLVData,
 												Value: []byte{1, 2, 3, 4},
 											},
+											{
+												Tag:   wire.ICBMTLVWantEvents,
+												Value: []byte{},
+											},
 										},
 									},
 								},
@@ -161,14 +161,14 @@ func TestICBMService_ChannelMsgToHost(t *testing.T) {
 									TLVUserInfo: newTestSession("sender-screen-name", sessOptWarning(10)).TLVUserInfo(),
 									TLVRestBlock: wire.TLVRestBlock{
 										TLVList: wire.TLVList{
-											{
-												Tag:   wire.ICBMTLVWantEvents,
-												Value: []byte{},
-											},
 											{
 												Tag:   wire.ICBMTLVData,
 												Value: []byte{1, 2, 3, 4},
 											},
+											{
+												Tag:   wire.ICBMTLVWantEvents,
+												Value: []byte{},
+											},
 										},
 									},
 								},
@@ -486,7 +486,6 @@ func TestICBMService_ChannelMsgToHost(t *testing.T) {
 									TLVUserInfo: newTestSession("sender-screen-name", sessOptWarning(10)).TLVUserInfo(),
 									TLVRestBlock: wire.TLVRestBlock{
 										TLVList: wire.TLVList{
-											wire.NewTLVBE(wire.ICBMTLVWantEvents, []byte{}),
 											wire.NewTLVBE(wire.ICBMTLVData, wire.ICBMCh2Fragment{
 												Type:       wire.ICBMRdvMessagePropose,
 												Capability: wire.CapFileTransfer,
@@ -498,6 +497,7 @@ func TestICBMService_ChannelMsgToHost(t *testing.T) {
 													},
 												},
 											}),
+											wire.NewTLVBE(wire.ICBMTLVWantEvents, []byte{}),
 										},
 									},
 								},
@@ -573,11 +573,11 @@ func TestICBMService_ChannelMsgToHost(t *testing.T) {
 									TLVUserInfo: newTestSession("sender-screen-name", sessOptWarning(10)).TLVUserInfo(),
 									TLVRestBlock: wire.TLVRestBlock{
 										TLVList: wire.TLVList{
-											wire.NewTLVBE(wire.ICBMTLVWantEvents, []byte{}),
 											wire.NewTLVBE(wire.ICBMTLVData, wire.ICBMCh2Fragment{
 												Type:       wire.ICBMRdvMessageCancel,
 												Capability: wire.CapFileTransfer,
 											}),
+											wire.NewTLVBE(wire.ICBMTLVWantEvents, []byte{}),
 										},
 									},
 								},
@@ -646,7 +646,6 @@ func TestICBMService_ChannelMsgToHost(t *testing.T) {
 									TLVUserInfo: newTestSession("sender-screen-name", sessOptWarning(10)).TLVUserInfo(),
 									TLVRestBlock: wire.TLVRestBlock{
 										TLVList: wire.TLVList{
-											wire.NewTLVBE(wire.ICBMTLVWantEvents, []byte{}),
 											wire.NewTLVBE(wire.ICBMTLVData, wire.ICBMCh2Fragment{
 												Type:       wire.ICBMRdvMessagePropose,
 												Capability: wire.CapFileTransfer,
@@ -657,6 +656,7 @@ func TestICBMService_ChannelMsgToHost(t *testing.T) {
 													},
 												},
 											}),
+											wire.NewTLVBE(wire.ICBMTLVWantEvents, []byte{}),
 										},
 									},
 								},