Skip to content

Commit 40c89ec

Browse files
committed
fmt and lint issues; init tests/
1 parent 2583e88 commit 40c89ec

File tree

10 files changed

+179
-155
lines changed

10 files changed

+179
-155
lines changed

docs/DEV.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ Type `next` or `n`:
140140
Warning: debugging optimized function
141141
52: //broadcast the request
142142
53: for i := 0; i < cl.Cfg.N; i++ {
143-
54: //req := Request{RequestInner{cl.Cfg.N,0, 0, TYPE_REQU, MsgType(msg), timeStamp, nil}, "", msgSignature{nil, nil}} // the N-th party is the client
144-
55: req := Request{RequestInner{cl.Cfg.N, 0, 0, TYPE_REQU, MsgType(msg), timeStamp}, "", MsgSignature{nil, nil}} // the N-th party is the client
143+
54: //req := Request{RequestInner{cl.Cfg.N,0, 0, typeRequest, MsgType(msg), timeStamp, nil}, "", msgSignature{nil, nil}} // the N-th party is the client
144+
55: req := Request{RequestInner{cl.Cfg.N, 0, 0, typeRequest, MsgType(msg), timeStamp}, "", MsgSignature{nil, nil}} // the N-th party is the client
145145
56: //req.inner.outer = &req
146146
=> 57: req.addSig(&cl.privKey)
147147
58: arg := ProxyNewClientRequestArg{req, cl.Me}
@@ -182,7 +182,7 @@ hmmm, what's cl anyway?
182182
"127.0.0.1",
183183
],
184184
Ports: []int len: 4, cap: 4, [40540,40541,40542,40543],
185-
HOSTS_FILE: "/home/username/hosts",},
185+
HostsFile: "/home/username/hosts",},
186186
privKey: crypto/ecdsa.PrivateKey {
187187
PublicKey: (*crypto/ecdsa.PublicKey)(0xc4201fa030),
188188
D: *math/big.Int nil,},

docs/TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pbft-core/node.go:653:43: cannot use nil as type Request in field value
3131
- [ ] Add checkpoint support
3232
- [ ] add counter whenever we found a PREP
3333
- [ ] nd.broadcast(viewChange) // TODO broadcast view change RPC path.
34-
- [ ] func (nd *Node) NewClientRequest(req Request, clientId int) { // TODO change to single arg and single reply
34+
- [ ] func (nd *Node) NewClientRequest(req Request, clientID int) { // TODO change to single arg and single reply
3535
- [ ] nd.broadcast(m) // TODO broadcast pre-prepare RPC path.
3636
- [ ] initialize ECDSA keys and hello signature
3737
- [ ] if ok && val.dig == dig { // TODO check the diff!

engine.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,24 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
//"fmt"
20+
"./pbft-core"
21+
"fmt"
2122
"os"
2223
"path"
23-
//"log"
24-
"fmt"
2524
"strconv"
26-
27-
"./pbft-core"
2825
"time"
2926
)
3027

31-
// NumQuest is the number of requests sent from client
32-
const NumQuest = 100
33-
3428
func main() {
3529

3630
cfg := pbft.Config{}
37-
cfg.HOSTS_FILE = path.Join(os.Getenv("HOME"), "hosts")
38-
cfg.IPList, cfg.Ports = pbft.GetIPConfigs(cfg.HOSTS_FILE)
31+
cfg.HostsFile = path.Join(os.Getenv("HOME"), "hosts")
32+
cfg.IPList, cfg.Ports = pbft.GetIPConfigs(cfg.HostsFile)
3933
fmt.Printf("Get IPList %v, Ports %v\n", cfg.IPList, cfg.Ports)
40-
cfg.N = len(cfg.IPList) - 1 // we assume the number of client is 1
41-
// cfg.GenerateKeys()
42-
cfg.GenerateKeysToFile()
43-
/////////////////
34+
cfg.NumKeys = len(cfg.IPList)
35+
cfg.N = cfg.NumKeys - 1 // we assume client count to be 1
36+
cfg.NumQuest = 100
37+
cfg.GenerateKeysToFile(cfg.NumKeys)
4438

4539
svList := make([]*pbft.Server, cfg.N)
4640
for i := 0; i < cfg.N; i++ {
@@ -56,10 +50,10 @@ func main() {
5650
}
5751
fmt.Println("[!!!] Please allow the program to accept incoming connections if you are using Mac OS.")
5852
time.Sleep(1 * time.Second) // wait for the servers to accept incoming connections
59-
/////////////////
53+
6054
cl := pbft.BuildClient(cfg, cfg.IPList[cfg.N], cfg.Ports[cfg.N], 0)
6155
start := time.Now()
62-
for k := 0; k < NumQuest; k++ {
56+
for k := 0; k < cfg.NumQuest; k++ {
6357
cl.NewRequest("Request "+strconv.Itoa(k), int64(k))
6458
}
6559
fmt.Println("Finish sending the requests.")
@@ -68,7 +62,7 @@ func main() {
6862
go func(ind int) {
6963
for {
7064
c := <-svList[ind].Out
71-
if c.Index == NumQuest {
65+
if c.Index == cfg.NumQuest {
7266
finish <- true
7367
}
7468
}

pbft-core/client.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,13 @@ limitations under the License.
1717
package pbft
1818

1919
import (
20-
"net/rpc"
21-
//"path"
22-
//"os"
23-
"strconv"
24-
//"fmt"
25-
//"bytes"
2620
"crypto/ecdsa"
27-
//"encoding/gob"
2821
"fmt"
29-
//"io/ioutil"
22+
"net/rpc"
3023
"path"
24+
"strconv"
3125
)
3226

33-
// import "fmt"
34-
// import "net"
35-
3627
type Client struct {
3728
IP string
3829
Port int
@@ -51,8 +42,8 @@ func (cl *Client) Start() {
5142
func (cl *Client) NewRequest(msg string, timeStamp int64) {
5243
//broadcast the request
5344
for i := 0; i < cl.Cfg.N; i++ {
54-
//req := Request{RequestInner{cl.Cfg.N,0, 0, TYPE_REQU, MsgType(msg), timeStamp, nil}, "", msgSignature{nil, nil}} // the N-th party is the client
55-
req := Request{RequestInner{cl.Cfg.N, 0, 0, TYPE_REQU, MsgType(msg), timeStamp}, "", MsgSignature{nil, nil}} // the N-th party is the client
45+
//req := Request{RequestInner{cl.Cfg.N,0, 0, typeRequest, MsgType(msg), timeStamp, nil}, "", msgSignature{nil, nil}} // the N-th party is the client
46+
req := Request{RequestInner{cl.Cfg.N, 0, 0, typeRequest, MsgType(msg), timeStamp}, "", MsgSignature{nil, nil}} // the N-th party is the client
5647
//req.inner.outer = &req
5748
req.addSig(cl.privKey)
5849
arg := ProxyNewClientRequestArg{req, cl.Me}
@@ -78,7 +69,6 @@ func BuildClient(cfg Config, IP string, Port int, me int) *Client {
7869
cl.peers = peers
7970
pemkeyFile := fmt.Sprintf("sign%v.pem", cfg.N)
8071
sk := FetchPrivateKey(path.Join(cfg.KD, pemkeyFile))
81-
// sk := cfg.Keys[cfg.N]
8272
fmt.Println("just fetched private key for Client")
8373
fmt.Println(sk)
8474
cl.privKey = sk

pbft-core/config.go

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,32 @@ limitations under the License.
1717
package pbft
1818

1919
import (
20-
// "fmt"
21-
// "log"
22-
// "os"
23-
"crypto/ecdsa"
24-
"crypto/elliptic"
2520
"path"
26-
//"fmt"
27-
//"bytes"
28-
//"encoding/gob"
29-
//"io/ioutil"
30-
//"log"
31-
"crypto/rand"
3221
)
3322

34-
// const PORT_NUMBER = 40623
35-
// const MAX_FAIL = 1
36-
const OUTPUT_THRESHOLD = 0
37-
const BASE_PORT = 40540
23+
// MaxFail defines the number of faults to be tolerated
24+
const MaxFail = 1
25+
const OutputThreshold = 0
3826

39-
const NUM_KEYS = 10
27+
// BasePort is used as base value of ports defined for initializng PBFT servers
28+
const BasePort = 40540
4029

4130
type Config struct {
42-
N int
43-
KD string
44-
LD string
45-
IPList []string
46-
Ports []int
47-
HOSTS_FILE string
48-
Keys []*ecdsa.PrivateKey
31+
N int // number of nodes to be launchedt
32+
KD string // key directory where pub/priva ECDSA keys are stored
33+
LD string // log directory
34+
IPList []string // stores list of IP addresses belonging to BFT nodes
35+
Ports []int // stores list of Ports belonging to BFT nodes
36+
HostsFile string // network config file, to read IP addresses from
37+
NumQuest int // NumQuest is the number of requests sent from client
38+
NumKeys int // NumKeys is the count of IP addresses (BFT nodes) participating
4939
}
5040

51-
// type DecodeParams struct {
52-
// pemEncoded, pemEncodedPub []byte
53-
// ktype string // ktype is whether public/private/both(nil)
54-
// }
55-
56-
func (cfg *Config) GenerateKeys() {
57-
cfg.Keys = make([]*ecdsa.PrivateKey, NUM_KEYS)
58-
for k := 0; k < NUM_KEYS; k++ {
59-
sk, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
60-
cfg.Keys[k] = sk
61-
}
62-
}
63-
64-
func (cfg *Config) GenerateKeysToFile() {
65-
IdCount := 1000
41+
// GenerateKeysToFile generates ECDSA public-private keypairs to a folder
42+
func (cfg *Config) GenerateKeysToFile(numKeys int) {
43+
// IdCount := 1000
6644
cfg.KD = path.Join(GetCWD(), "keys/")
6745
MakeDirIfNot(cfg.KD)
68-
WriteNewKeys(IdCount, cfg.KD)
69-
MyPrint(1, "Generated %d keys in %s folder..\n", IdCount, cfg.KD)
46+
WriteNewKeys(numKeys, cfg.KD)
47+
MyPrint(1, "Generated %d keypairs in %s folder..\n", numKeys, cfg.KD)
7048
}

0 commit comments

Comments
 (0)