/
internalchannel.go
90 lines (80 loc) · 2.87 KB
/
internalchannel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package internal
import (
"fmt"
"github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer"
cbg "github.com/whyrusleeping/cbor-gen"
datatransfer "github.com/filecoin-project/go-data-transfer"
)
//go:generate cbor-gen-for --map-encoding ChannelState EncodedVoucher EncodedVoucherResult
// EncodedVoucher is how the voucher is stored on disk
type EncodedVoucher struct {
// Vouchers identifier for decoding
Type datatransfer.TypeIdentifier
// used to verify this channel
Voucher *cbg.Deferred
}
// EncodedVoucherResult is how the voucher result is stored on disk
type EncodedVoucherResult struct {
// Vouchers identifier for decoding
Type datatransfer.TypeIdentifier
// used to verify this channel
VoucherResult *cbg.Deferred
}
// ChannelState is the internal representation on disk for the channel fsm
type ChannelState struct {
// PeerId of the manager peer
SelfPeer peer.ID
// an identifier for this channel shared by request and responder, set by requester through protocol
TransferID datatransfer.TransferID
// Initiator is the person who intiated this datatransfer request
Initiator peer.ID
// Responder is the person who is responding to this datatransfer request
Responder peer.ID
// base CID for the piece being transferred
BaseCid cid.Cid
// portion of Piece to return, specified by an IPLD selector
Selector *cbg.Deferred
// the party that is sending the data (not who initiated the request)
Sender peer.ID
// the party that is receiving the data (not who initiated the request)
Recipient peer.ID
// expected amount of data to be transferred
TotalSize uint64
// current status of this deal
Status datatransfer.Status
// total bytes read from this node and queued for sending (0 if receiver)
Queued uint64
// total bytes sent from this node (0 if receiver)
Sent uint64
// total bytes received by this node (0 if sender)
Received uint64
// more informative status on a channel
Message string
Vouchers []EncodedVoucher
VoucherResults []EncodedVoucherResult
// Number of blocks that have been received, including blocks that are
// present in more than one place in the DAG
ReceivedBlocksTotal int64
// Number of blocks that have been queued, including blocks that are
// present in more than one place in the DAG
QueuedBlocksTotal int64
// Number of blocks that have been sent, including blocks that are
// present in more than one place in the DAG
SentBlocksTotal int64
// Stages traces the execution fo a data transfer.
//
// EXPERIMENTAL; subject to change.
Stages *datatransfer.ChannelStages
}
// AddLog takes an fmt string with arguments, and adds the formatted string to
// the logs for the current deal stage.
//
// EXPERIMENTAL; subject to change.
func (cs *ChannelState) AddLog(msg string, a ...interface{}) {
if len(a) > 0 {
msg = fmt.Sprintf(msg, a...)
}
stage := datatransfer.Statuses[cs.Status]
cs.Stages.AddLog(stage, msg)
}