两种拜占庭算法

方法一:

package main

import (
    "fmt"
    "time"
)
var ch = make(chan  string)
var t=[4]int{1}

func aa(cnt int){
    for i:=0;i<4;i++{
        if i!=cnt {
            t[i] = t[cnt]+t[i]
            fmt.Println(t)
        }
    }
}
func main() {
    fmt.Println(t)
    go func () {
        cnt:=0
        for {
            msg:=<-ch
            fmt.Println(msg)
            aa(cnt)
        }
    }()
    go func() {
        time.Sleep(time.Second)
        ch<-"1"
    }()

    for {}
}

方法二:

package main

import "fmt"

type Node struct {
    name string
    data int
}

var n = [4]Node{
    Node{"N0", 0},
    Node{"N1", 0},
    Node{"N2", 0},
    Node{"N3", 0},
}

func main() {
    n[0].data = 1

    for i:=0;i<len(n);i++ {
        for j:=0;j<len(n) ;j++  {
            if i==j {
                continue
            }
            n[j].data = n[j].data+1
        }
        fmt.Println(n)
    }
}

你可能感兴趣的:(DBFT)