bip_handshake/message/
complete.rs

1use std::net::SocketAddr;
2
3use message::protocol::Protocol;
4use message::extensions::{Extensions};
5
6use bip_util::bt::{InfoHash, PeerId};
7
8/// Message containing completed handshaking information.
9pub struct CompleteMessage<S> {
10    prot: Protocol,
11    ext:  Extensions,
12    hash: InfoHash,
13    pid:  PeerId,
14    addr: SocketAddr,
15    sock: S
16}
17
18impl<S> CompleteMessage<S> {
19    /// Create a new `CompleteMessage` over the given socket S.
20    pub fn new(prot: Protocol, ext: Extensions, hash: InfoHash, pid: PeerId, addr: SocketAddr, sock: S) -> CompleteMessage<S> {
21        CompleteMessage{ prot: prot, ext: ext, hash: hash, pid: pid, addr: addr, sock: sock }
22    }
23
24    /// Protocol that this peer is operating over.
25    pub fn protocol(&self) -> &Protocol {
26        &self.prot
27    }
28
29    /// Extensions that both you and the peer support.
30    pub fn extensions(&self) -> &Extensions {
31        &self.ext
32    }
33
34    /// Hash that the peer is interested in.
35    pub fn hash(&self) -> &InfoHash {
36        &self.hash
37    }
38
39    /// Id that the peer has given itself.
40    pub fn peer_id(&self) -> &PeerId {
41        &self.pid
42    }
43
44    /// Address the peer is connected to us on.
45    pub fn address(&self) -> &SocketAddr {
46        &self.addr
47    }
48
49    /// Socket of some type S, that we use to communicate with the peer.
50    pub fn socket(&self) -> &S {
51        &self.sock
52    }
53
54    /// Break the `CompleteMessage` into its parts.
55    pub fn into_parts(self) -> (Protocol, Extensions, InfoHash, PeerId, SocketAddr, S) {
56        (self.prot, self.ext, self.hash, self.pid, self.addr, self.sock)
57    }
58}