-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsenso_bamba.go
More file actions
61 lines (44 loc) · 860 Bytes
/
consenso_bamba.go
File metadata and controls
61 lines (44 loc) · 860 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"net"
"bufio"
)
var nodes int = 0
var inputs []string;
func main(){
host := fmt.Sprintf("%s:8000", "localhost")
ln, _ := net.Listen("tcp", host)
go consensus()
defer ln.Close()
for {
con, _ := ln.Accept()
fmt.Println("Conectado!")
nodes++
go handle(con)
}
}
func handle(con net.Conn){
defer con.Close()
r := bufio.NewReader(con)
msg, _ := r.ReadString('\n')
fmt.Println(msg)
inputs = append(inputs, msg)
}
func consensus(){
for len(inputs) == 0 || len(inputs) != nodes {
}
counterMap := make(map[string]int)
for i:= 0; i < nodes; i++ {
counterMap[inputs[i]]++
}
max := 0
result := ""
for i, val := range counterMap {
if val > max {
max = val
result = i
}
}
fmt.Println("La mayoria es: " + result + "!!!")
}