mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-13 17:46:39 +00:00

* [NOD-122] Handle each message in rpcclient with a separate goroutine * [NOD-122] Stop listening to new blocks when not mining * [NOD-122] Made RPC logging in mining simulator more explicit + some styling enhencement
49 lines
951 B
Go
49 lines
951 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/daglabs/btcd/rpcclient"
|
|
)
|
|
|
|
func connectToServers(cfg *config, addressList []string) ([]*simulatorClient, error) {
|
|
clients := make([]*simulatorClient, len(addressList))
|
|
|
|
var cert []byte
|
|
if !cfg.DisableTLS {
|
|
var err error
|
|
cert, err = ioutil.ReadFile(cfg.CertificatePath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Error reading certificates file: %s", err)
|
|
}
|
|
}
|
|
|
|
for i, address := range addressList {
|
|
connCfg := &rpcclient.ConnConfig{
|
|
Host: address,
|
|
Endpoint: "ws",
|
|
User: "user",
|
|
Pass: "pass",
|
|
DisableTLS: cfg.DisableTLS,
|
|
RequestTimeout: time.Second / 2,
|
|
}
|
|
|
|
if !cfg.DisableTLS {
|
|
connCfg.Certificates = cert
|
|
}
|
|
|
|
var err error
|
|
clients[i], err = newSimulatorClient(address, connCfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
log.Printf("Connected to server %s", address)
|
|
}
|
|
|
|
return clients, nil
|
|
}
|