Convert to default net ports provided by btcnet.

ok @jrick
This commit is contained in:
Dave Collins 2014-05-29 12:35:09 -05:00
parent 74303966c0
commit 252c022644
4 changed files with 19 additions and 27 deletions

View File

@ -481,7 +481,7 @@ func loadConfig() (*config, []string, error) {
// we are to connect to.
if len(cfg.Listeners) == 0 {
cfg.Listeners = []string{
net.JoinHostPort("", activeNetParams.listenPort),
net.JoinHostPort("", activeNetParams.DefaultPort),
}
}
@ -545,7 +545,7 @@ func loadConfig() (*config, []string, error) {
// Add default port to all listener addresses if needed and remove
// duplicate addresses.
cfg.Listeners = normalizeAddresses(cfg.Listeners,
activeNetParams.listenPort)
activeNetParams.DefaultPort)
// Add default port to all rpc listener addresses if needed and remove
// duplicate addresses.
@ -555,9 +555,9 @@ func loadConfig() (*config, []string, error) {
// Add default port to all added peer addresses if needed and remove
// duplicate addresses.
cfg.AddPeers = normalizeAddresses(cfg.AddPeers,
activeNetParams.peerPort)
activeNetParams.DefaultPort)
cfg.ConnectPeers = normalizeAddresses(cfg.ConnectPeers,
activeNetParams.peerPort)
activeNetParams.DefaultPort)
// Setup dial and DNS resolution (lookup) functions depending on the
// specified options. The default is to use the standard net.Dial

View File

@ -17,10 +17,8 @@ var activeNetParams = &mainNetParams
// network and test networks.
type params struct {
*btcnet.Params
peerPort string
listenPort string
rpcPort string
dnsSeeds []string
rpcPort string
dnsSeeds []string
}
// mainNetParams contains parameters specific to the main network
@ -30,10 +28,8 @@ type params struct {
// it does not handle on to btcd. This approach allows the wallet process
// to emulate the full reference implementation RPC API.
var mainNetParams = params{
Params: &btcnet.MainNetParams,
listenPort: btcwire.MainPort,
peerPort: btcwire.MainPort,
rpcPort: "8334",
Params: &btcnet.MainNetParams,
rpcPort: "8334",
dnsSeeds: []string{
"seed.bitcoin.sipa.be",
"dnsseed.bluematt.me",
@ -49,21 +45,17 @@ var mainNetParams = params{
// than the reference implementation - see the mainNetParams comment for
// details.
var regressionNetParams = params{
Params: &btcnet.RegressionNetParams,
listenPort: btcwire.RegressionTestPort,
peerPort: btcwire.TestNetPort,
rpcPort: "18334",
dnsSeeds: []string{},
Params: &btcnet.RegressionNetParams,
rpcPort: "18334",
dnsSeeds: []string{},
}
// testNet3Params contains parameters specific to the test network (version 3)
// (btcwire.TestNet3). NOTE: The RPC port is intentionally different than the
// reference implementation - see the mainNetParams comment for details.
var testNet3Params = params{
Params: &btcnet.TestNet3Params,
listenPort: btcwire.TestNetPort,
peerPort: btcwire.TestNetPort,
rpcPort: "18334",
Params: &btcnet.TestNet3Params,
rpcPort: "18334",
dnsSeeds: []string{
"testnet-seed.bitcoin.petertodd.org",
"testnet-seed.bluematt.me",

View File

@ -513,7 +513,7 @@ func handleAskWallet(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
func handleAddNode(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
c := cmd.(*btcjson.AddNodeCmd)
addr := normalizeAddress(c.Addr, activeNetParams.peerPort)
addr := normalizeAddress(c.Addr, activeNetParams.DefaultPort)
var err error
switch c.SubCmd {
case "add":

View File

@ -468,7 +468,7 @@ func (s *server) seedFromDNS() {
}
addresses := make([]*btcwire.NetAddress, len(seedpeers))
// if this errors then we have *real* problems
intPort, _ := strconv.Atoi(activeNetParams.peerPort)
intPort, _ := strconv.Atoi(activeNetParams.DefaultPort)
for i, peer := range seedpeers {
addresses[i] = new(btcwire.NetAddress)
addresses[i].SetAddress(peer, uint16(intPort))
@ -621,7 +621,7 @@ out:
// allow nondefault ports after 50 failed tries.
if fmt.Sprintf("%d", addr.na.Port) !=
activeNetParams.peerPort && tries < 50 {
activeNetParams.DefaultPort && tries < 50 {
continue
}
@ -956,7 +956,7 @@ func (s *server) upnpUpdateThread() {
// Go off immediately to prevent code duplication, thereafter we renew
// lease every 15 minutes.
timer := time.NewTimer(0 * time.Second)
lport, _ := strconv.ParseInt(activeNetParams.listenPort, 10, 16)
lport, _ := strconv.ParseInt(activeNetParams.DefaultPort, 10, 16)
first := true
out:
for {
@ -1028,7 +1028,7 @@ func newServer(listenAddrs []string, db btcdb.Db, netParams *btcnet.Params) (*se
discover = false
// if this fails we have real issues.
port, _ := strconv.ParseUint(
activeNetParams.listenPort, 10, 16)
activeNetParams.DefaultPort, 10, 16)
for _, sip := range cfg.ExternalIPs {
eport := uint16(port)
@ -1069,7 +1069,7 @@ func newServer(listenAddrs []string, db btcdb.Db, netParams *btcnet.Params) (*se
// TODO(oga) nonstandard port...
if wildcard {
port, err :=
strconv.ParseUint(activeNetParams.listenPort,
strconv.ParseUint(activeNetParams.DefaultPort,
10, 16)
if err != nil {
// I can't think of a cleaner way to do this...