aboutsummaryrefslogtreecommitdiffstats
path: root/simulation/app.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-09-11 14:56:47 +0800
committerGitHub <noreply@github.com>2018-09-11 14:56:47 +0800
commit292ad73ec08621fa9beef5f028860131fcbf9bd9 (patch)
tree47644eaad7757cd2e8798ae7fe361fa5d6e99060 /simulation/app.go
parent582a491aa0bcb784ac7b65ebbfb42139945ea703 (diff)
downloaddexon-consensus-292ad73ec08621fa9beef5f028860131fcbf9bd9.tar
dexon-consensus-292ad73ec08621fa9beef5f028860131fcbf9bd9.tar.gz
dexon-consensus-292ad73ec08621fa9beef5f028860131fcbf9bd9.tar.bz2
dexon-consensus-292ad73ec08621fa9beef5f028860131fcbf9bd9.tar.lz
dexon-consensus-292ad73ec08621fa9beef5f028860131fcbf9bd9.tar.xz
dexon-consensus-292ad73ec08621fa9beef5f028860131fcbf9bd9.tar.zst
dexon-consensus-292ad73ec08621fa9beef5f028860131fcbf9bd9.zip
simulation: integrate test.Transport (#99)
- Add marshaller for simulation by encoding/json - Implement peer server based on test.TranportServer - Remove network models, they are replaced with test.LatencyModel
Diffstat (limited to 'simulation/app.go')
-rw-r--r--simulation/app.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/simulation/app.go b/simulation/app.go
index 5a31273..c312204 100644
--- a/simulation/app.go
+++ b/simulation/app.go
@@ -32,7 +32,7 @@ type simApp struct {
ValidatorID types.ValidatorID
Outputs []*types.Block
Early bool
- Network PeerServerNetwork
+ netModule *network
DeliverID int
// blockSeen stores the time when block is delivered by Total Ordering.
blockSeen map[common.Hash]time.Time
@@ -43,10 +43,10 @@ type simApp struct {
}
// newSimApp returns point to a new instance of simApp.
-func newSimApp(id types.ValidatorID, Network PeerServerNetwork) *simApp {
+func newSimApp(id types.ValidatorID, netModule *network) *simApp {
return &simApp{
ValidatorID: id,
- Network: Network,
+ netModule: netModule,
DeliverID: 0,
blockSeen: make(map[common.Hash]time.Time),
unconfirmedBlocks: make(map[types.ValidatorID]common.Hashes),
@@ -120,7 +120,7 @@ func (a *simApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool) {
confirmLatency := []time.Duration{}
- payload := []TimestampMessage{}
+ payload := []timestampMessage{}
for _, block := range blocks {
if block.ProposerID == a.ValidatorID {
confirmLatency = append(confirmLatency,
@@ -128,7 +128,7 @@ func (a *simApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool) {
}
for hash := range block.Acks {
for _, blockHash := range a.getAckedBlocks(hash) {
- payload = append(payload, TimestampMessage{
+ payload = append(payload, timestampMessage{
BlockHash: blockHash,
Event: timestampAck,
Timestamp: now,
@@ -142,20 +142,20 @@ func (a *simApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool) {
if err != nil {
fmt.Println(err)
} else {
- msg := Message{
+ msg := &message{
Type: blockTimestamp,
Payload: jsonPayload,
}
- a.Network.NotifyServer(msg)
+ a.netModule.report(msg)
}
}
- blockList := BlockList{
+ blockList := &BlockList{
ID: a.DeliverID,
BlockHash: blockHashes,
ConfirmLatency: confirmLatency,
}
- a.Network.DeliverBlocks(blockList)
+ a.netModule.report(blockList)
a.DeliverID++
for _, block := range blocks {
a.blockSeen[block.Hash] = now
@@ -171,7 +171,7 @@ func (a *simApp) DeliverBlock(blockHash common.Hash, timestamp time.Time) {
return
}
now := time.Now()
- payload := []TimestampMessage{
+ payload := []timestampMessage{
{
BlockHash: blockHash,
Event: blockSeen,
@@ -188,11 +188,11 @@ func (a *simApp) DeliverBlock(blockHash common.Hash, timestamp time.Time) {
fmt.Println(err)
return
}
- msg := Message{
+ msg := &message{
Type: blockTimestamp,
Payload: jsonPayload,
}
- a.Network.NotifyServer(msg)
+ a.netModule.report(msg)
}
// NotaryAckDeliver is called when a notary ack is created.