github.com/amazechain/amc@v0.1.3/internal/download/dispatcher.go (about) 1 // Copyright 2022 The AmazeChain Authors 2 // This file is part of the AmazeChain library. 3 // 4 // The AmazeChain library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The AmazeChain library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package download 18 19 import "time" 20 import "github.com/libp2p/go-libp2p/core/peer" 21 22 type Request struct { 23 peer *peer.ID 24 id uint64 25 26 sink chan *Response // Channel to deliver the response on 27 cancel chan struct{} // Channel to cancel requests ahead of time 28 29 code uint64 // Message code of the request packet 30 want uint64 // Message code of the response packet 31 data interface{} // Data content of the request packet 32 33 Peer string // Demultiplexer if cross-peer requests are batched together 34 Sent time.Time // Timestamp when the request was sent 35 } 36 37 type request struct { 38 req *Request 39 fail chan error 40 } 41 42 type Response struct { 43 id uint64 // Request ID to match up this reply to 44 recv time.Time // Timestamp when the request was received 45 code uint64 // Response packet type to cross validate with request 46 47 Req *request // Original request to cross-reference with 48 Res interface{} // Remote response for the request query 49 Meta interface{} // Metadata generated locally on the receiver thread 50 Time time.Duration // Time it took for the request to be served 51 Done chan error // Channel to signal message handling to the reader 52 } 53 54 type response struct { 55 res *Response 56 fail chan error 57 }