Skip to content

Commit

Permalink
Merge d1553b9 into 1426602
Browse files Browse the repository at this point in the history
  • Loading branch information
divyakoshy committed Jul 31, 2018
2 parents 1426602 + d1553b9 commit 9bf07a4
Show file tree
Hide file tree
Showing 63 changed files with 2,492 additions and 2,289 deletions.
2 changes: 1 addition & 1 deletion .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

go build ./...
GOMAXPROCS=1 CI=true ginkgo -v --race --cover --coverprofile coverprofile.out ./...
covermerge crypto/coverprofile.out dht/coverprofile.out dispatch/coverprofile.out grpc/coverprofile.out http/coverprofile.out http/adapter/coverprofile.out identity/coverprofile.out leveldb/coverprofile.out logger/coverprofile.out ome/coverprofile.out order/coverprofile.out orderbook/coverprofile.out shamir/coverprofile.out smpc/coverprofile.out stackint/coverprofile.out stream/coverprofile.out swarm/coverprofile.out > coverprofile.out
covermerge crypto/coverprofile.out dispatch/coverprofile.out grpc/coverprofile.out http/coverprofile.out http/adapter/coverprofile.out identity/coverprofile.out leveldb/coverprofile.out logger/coverprofile.out ome/coverprofile.out order/coverprofile.out orderbook/coverprofile.out shamir/coverprofile.out smpc/coverprofile.out stackint/coverprofile.out stream/coverprofile.out swarm/coverprofile.out > coverprofile.out

sed -i '/.pb.go/d' coverprofile.out
sed -i '/bindings/d' coverprofile.out
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ script:
# - golint -set_exit_status `go list ./... | grep -Ev "(stackint/asm|vendor)"`
# - golint `go list ./... | grep -Ev "(stackint/asm|vendor)"`
- ginkgo --race --cover --coverprofile coverprofile.out ./...
- covermerge crypto/coverprofile.out dht/coverprofile.out dispatch/coverprofile.out grpc/coverprofile.out http/coverprofile.out http/adapter/coverprofile.out identity/coverprofile.out leveldb/coverprofile.out logger/coverprofile.out ome/coverprofile.out order/coverprofile.out orderbook/coverprofile.out shamir/coverprofile.out smpc/coverprofile.out stackint/coverprofile.out stream/coverprofile.out swarm/coverprofile.out > coverprofile.out
- covermerge crypto/coverprofile.out dispatch/coverprofile.out grpc/coverprofile.out http/coverprofile.out http/adapter/coverprofile.out identity/coverprofile.out leveldb/coverprofile.out logger/coverprofile.out ome/coverprofile.out order/coverprofile.out orderbook/coverprofile.out shamir/coverprofile.out smpc/coverprofile.out stackint/coverprofile.out stream/coverprofile.out swarm/coverprofile.out > coverprofile.out
- sed -i '/.pb.go/d' coverprofile.out # autogenerated files
- sed -i '/bindings/d' coverprofile.out # autogenerated files
- sed -i '/cmd/d' coverprofile.out # command-line files
Expand Down
54 changes: 0 additions & 54 deletions cmd/analysis/leveldb/main.go

This file was deleted.

77 changes: 0 additions & 77 deletions cmd/analysis/renLedger/main.go

This file was deleted.

106 changes: 0 additions & 106 deletions cmd/cancelOrder/cancelOrder.go

This file was deleted.

1 change: 1 addition & 0 deletions cmd/darknode/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Config struct {
BootstrapMultiAddresses identity.MultiAddresses `json:"bootstrapMultiAddresses"`
Host string `json:"host"`
Port string `json:"port"`
Alpha int `json:"alpha"`
}

func NewConfigFromJSONFile(filename string) (Config, error) {
Expand Down
55 changes: 40 additions & 15 deletions cmd/darknode/darknode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"log"
"math/rand"
"net"
netHttp "net/http"
"os"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/republicprotocol/republic-go/cmd/darknode/config"
"github.com/republicprotocol/republic-go/contract"
"github.com/republicprotocol/republic-go/crypto"
"github.com/republicprotocol/republic-go/dht"
"github.com/republicprotocol/republic-go/dispatch"
"github.com/republicprotocol/republic-go/grpc"
"github.com/republicprotocol/republic-go/http"
Expand Down Expand Up @@ -84,6 +84,7 @@ func main() {
log.Fatalf("cannot sign own multiaddress: %v", err)
}
multiAddr.Signature = multiAddrSignature
multiAddr.Nonce = 1

// New database for persistent storage
store, err := leveldb.NewStore(*dataParam, 72*time.Hour)
Expand All @@ -92,18 +93,21 @@ func main() {
}
defer store.Release()

// New DHT
dht := dht.NewDHT(config.Address, 64)
// Get own nonce from leveldb, if present and store multiaddress.
_, err = store.SwarmMultiAddressStore().MultiAddress(multiAddr.Address())
if err != nil && err != swarm.ErrMultiAddressNotFound {
logger.Network(logger.LevelError, fmt.Sprintf("error retrieving own nonce details from store: %v", err))
}
if _, err := store.SwarmMultiAddressStore().PutMultiAddress(multiAddr); err != nil {
log.Fatalf("cannot store own multiaddress in leveldb: %v", err)
}

// New gRPC components
server := grpc.NewServer()

statusService := grpc.NewStatusService(&dht)
statusService.Register(server)

swarmClient := grpc.NewSwarmClient(multiAddr)
swarmService := grpc.NewSwarmService(swarm.NewServer(&crypter, swarmClient, &dht))
swarmer := swarm.NewSwarmer(swarmClient, &dht)
swarmClient := grpc.NewSwarmClient(store.SwarmMultiAddressStore(), multiAddr.Address())
swarmer := swarm.NewSwarmer(swarmClient, store.SwarmMultiAddressStore(), config.Alpha, &config.Keystore.EcdsaKey)
swarmService := grpc.NewSwarmService(swarm.NewServer(swarmer, store.SwarmMultiAddressStore(), config.Alpha), time.Millisecond)
swarmService.Register(server)

orderbook := orderbook.NewOrderbook(config.Keystore.RsaKey, store.OrderbookPointerStore(), store.OrderbookOrderStore(), store.OrderbookOrderFragmentStore(), &contractBinder, 5*time.Second, 32)
Expand All @@ -122,7 +126,7 @@ func main() {
}

// Populate status information
statusProvider := status.NewProvider(&dht)
statusProvider := status.NewProvider(swarmer)
statusProvider.WriteNetwork(string(conn.Config.Network))
statusProvider.WriteMultiAddress(multiAddr)
statusProvider.WriteEthereumNetwork(ethNetwork)
Expand Down Expand Up @@ -154,6 +158,7 @@ func main() {
go func() {
// Wait for the gRPC server to boot
time.Sleep(time.Second)
rand.Seed(time.Now().UnixNano())

// Wait until registration
isRegistered, err := contractBinder.IsRegistered(config.Address)
Expand All @@ -171,13 +176,19 @@ func main() {
// Bootstrap into the network
fmtStr := "bootstrapping\n"
for _, multiAddr := range config.BootstrapMultiAddresses {
// Get nonce of the bootstrap multiaddress, if present in the store.
_, err := store.SwarmMultiAddressStore().MultiAddress(multiAddr.Address())
if err != nil && err != swarm.ErrMultiAddressNotFound {
logger.Network(logger.LevelError, fmt.Sprintf("cannot get bootstrap nonce details from store: %v", err))
continue
}
if _, err := store.SwarmMultiAddressStore().PutMultiAddress(multiAddr); err != nil {
logger.Network(logger.LevelError, fmt.Sprintf("cannot store bootstrap multiaddress in store: %v", err))
}
fmtStr += " " + multiAddr.String() + "\n"
}
log.Printf(fmtStr)
if err := swarmer.Bootstrap(context.Background(), config.BootstrapMultiAddresses); err != nil {
log.Printf("bootstrap: %v", err)
}
log.Printf("connected to %v peers", len(dht.MultiAddresses()))
pingNetwork(swarmer)

// New secure multi-party computer
smpcer := smpc.NewSmpcer(connectorListener, swarmer)
Expand All @@ -203,6 +214,7 @@ func main() {
// Periodically sync the next ξ
for {
time.Sleep(5 * time.Second)
rand.Seed(time.Now().UnixNano())

// Get the epoch
nextEpoch, err := contractBinder.Epoch()
Expand All @@ -222,9 +234,11 @@ func main() {
ome.OnChangeEpoch(epoch)
}
}, func() {
// Prune the database every hour
// Prune the database every hour and update the network with the
// darknode address
for {
time.Sleep(time.Hour)
pingNetwork(swarmer)
store.Prune()
}
})
Expand Down Expand Up @@ -254,3 +268,14 @@ func getIPAddress() (string, error) {

return string(out), nil
}

func pingNetwork(swarmer swarm.Swarmer) {
if err := swarmer.Ping(context.Background()); err != nil {
log.Printf("cannot bootstrap: %v", err)
}
peers, err := swarmer.Peers()
if err != nil {
logger.Error(fmt.Sprintf("cannot get connected peers: %v", err))
}
log.Printf("connected to %v peers", len(peers)-1)
}

0 comments on commit 9bf07a4

Please sign in to comment.