/
promise.go
34 lines (29 loc) · 1003 Bytes
/
promise.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
package node
import (
"github.com/andrecronje/babble/src/hashgraph"
"github.com/andrecronje/babble/src/peers"
)
//JoinPromiseResponse is a struct returned by a Join Promise
type JoinPromiseResponse struct {
Accepted bool
AcceptedRound int
Peers []*peers.Peer
}
//JoinPromise is a struct for an asynchronous response to a Join Request
type JoinPromise struct {
Tx hashgraph.InternalTransaction
RespCh chan JoinPromiseResponse
}
//NewJoinPromise is a factory method for a JoinPromise
func NewJoinPromise(tx hashgraph.InternalTransaction) *JoinPromise {
return &JoinPromise{
Tx: tx,
//make buffered because we don't want to block if there is no listener.
//There might be something smarter to do here
RespCh: make(chan JoinPromiseResponse, 2),
}
}
//Respond handles sending a JoinPromiseResponse to a JoinPromise
func (p *JoinPromise) Respond(accepted bool, acceptedRound int, peers []*peers.Peer) {
p.RespCh <- JoinPromiseResponse{accepted, acceptedRound, peers}
}