Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store the count of unique Receieved cids #216

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions channelmonitor/channelmonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ func (m *mockChannelState) Status() datatransfer.Status {
return datatransfer.Ongoing
}

func (m *mockChannelState) NReceivedCids() uint64 {
panic("implement me")
}

func (m *mockChannelState) TransferID() datatransfer.TransferID {
panic("implement me")
}
Expand Down
7 changes: 7 additions & 0 deletions channels/channel_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type channelState struct {
voucherDecoder DecoderByTypeFunc
channelCIDsReader ChannelCIDsReader

nReceivedCids uint64

// stages tracks the timeline of events related to a data transfer, for
// traceability purposes.
stages *datatransfer.ChannelStages
Expand Down Expand Up @@ -107,6 +109,10 @@ func (c channelState) ReceivedCids() []cid.Cid {
return receivedCids
}

func (c channelState) NReceivedCids() uint64 {
return c.nReceivedCids
}

// Sender returns the peer id for the node that is sending data
func (c channelState) Sender() peer.ID { return c.sender }

Expand Down Expand Up @@ -211,6 +217,7 @@ func fromInternalChannelState(c internal.ChannelState, voucherDecoder DecoderByT
voucherDecoder: voucherDecoder,
channelCIDsReader: channelCIDsReader,
stages: c.Stages,
nReceivedCids: c.NReceivedCids,
}
}

Expand Down
1 change: 1 addition & 0 deletions channels/channels_fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var ChannelEvents = fsm.Events{
fsm.Event(datatransfer.DataReceivedProgress).FromMany(transferringStates...).ToNoChange().
Action(func(chst *internal.ChannelState, delta uint64) error {
chst.Received += delta
chst.NReceivedCids = chst.NReceivedCids + 1
chst.AddLog("received data")
return nil
}),
Expand Down
3 changes: 3 additions & 0 deletions channels/channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func TestChannels(t *testing.T) {
require.Equal(t, datatransfer.Requested, state.Status())
require.Equal(t, uint64(0), state.Received())
require.Equal(t, uint64(0), state.Sent())

require.Empty(t, state.ReceivedCids())

isNew, err := channelList.DataReceived(datatransfer.ChannelID{Initiator: peers[0], Responder: peers[1], ID: tid1}, cids[0], 50)
Expand All @@ -153,6 +154,7 @@ func TestChannels(t *testing.T) {
require.Equal(t, uint64(50), state.Received())
require.Equal(t, uint64(0), state.Sent())
require.Equal(t, []cid.Cid{cids[0]}, state.ReceivedCids())
require.Equal(t, uint64(1), state.NReceivedCids())

isNew, err = channelList.DataSent(datatransfer.ChannelID{Initiator: peers[0], Responder: peers[1], ID: tid1}, cids[1], 100)
require.NoError(t, err)
Expand Down Expand Up @@ -180,6 +182,7 @@ func TestChannels(t *testing.T) {
require.Equal(t, uint64(100), state.Received())
require.Equal(t, uint64(100), state.Sent())
require.Equal(t, []cid.Cid{cids[0], cids[1]}, state.ReceivedCids())
require.Equal(t, uint64(2), state.NReceivedCids())

isNew, err = channelList.DataSent(datatransfer.ChannelID{Initiator: peers[0], Responder: peers[1], ID: tid1}, cids[1], 25)
require.NoError(t, err)
Expand Down
3 changes: 3 additions & 0 deletions channels/internal/internalchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type ChannelState struct {
Vouchers []EncodedVoucher
VoucherResults []EncodedVoucherResult

// NReceivedCids is the number of cids for which data has already been received by this node.
NReceivedCids uint64

// Stages traces the execution fo a data transfer.
//
// EXPERIMENTAL; subject to change.
Expand Down
33 changes: 32 additions & 1 deletion channels/internal/internalchannel_cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ type ChannelState interface {
// ReceivedCids returns the cids received so far on the channel
ReceivedCids() []cid.Cid

// NReceivedCids returns the number of unique cids received on the channel.
NReceivedCids() uint64

// Queued returns the number of bytes read from the node and queued for sending
Queued() uint64

Expand Down