Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Nov 9, 2021
1 parent 90d200f commit 50ead6a
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 7 deletions.
38 changes: 38 additions & 0 deletions .devnet/alice.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM golang:1.17

ARG chain="polkadot"
ARG basepath="~/.gossamer"
# ARG DD_API_KEY

ENV GO111MODULE=on

ENV chain=${chain}
ENV basepath=${basepath}
# ENV DD_API_KEY=${DD_API_KEY}

# RUN ["sh", "-c", "DD_AGENT_MAJOR_VERSION=7 DD_INSTALL_ONLY=true DD_API_KEY=${DD_API_KEY} DD_SITE=\"datadoghq.com\" bash -c \"$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)\""]

WORKDIR /gossamer

COPY . .

# RUN ["sh", "-c", "mv .github/workflows/staging/openmetrics.d/${chain}-conf.yaml /etc/datadog-agent/conf.d/openmetrics.d/conf.yaml"]
# RUN ls -la /etc/datadog-agent/conf.d/openmetrics.d/
# RUN cat /etc/hosts
# RUN service datadog-agent start

RUN go get ./...
RUN go build github.com/ChainSafe/gossamer/cmd/gossamer

RUN gossamer --key alice init

# use a hardcoded key for alice, so we can determine what the peerID is for subsequent nodes

RUN cp devnet/alice.node.key ~/.gossamer/gssmr/node.key

RUN ls -la ~/.gossamer/gssmr

RUN cat ~/.gossamer/gssmr/node.key

ENTRYPOINT gossamer --key=alice --babe-lead --publish-metrics --rpc --rpc-external=true
EXPOSE 7001 8545 8546 8540 9876
32 changes: 32 additions & 0 deletions .devnet/bob.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM golang:1.17

ARG key
RUN test -n "$key"

# ARG DD_API_KEY

ENV GO111MODULE=on

ENV key=${key}
# ENV DD_API_KEY=${DD_API_KEY}

# RUN ["sh", "-c", "DD_AGENT_MAJOR_VERSION=7 DD_INSTALL_ONLY=true DD_API_KEY=${DD_API_KEY} DD_SITE=\"datadoghq.com\" bash -c \"$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)\""]

WORKDIR /gossamer

COPY . .

# RUN ["sh", "-c", "mv .github/workflows/staging/openmetrics.d/${chain}-conf.yaml /etc/datadog-agent/conf.d/openmetrics.d/conf.yaml"]
# RUN ls -la /etc/datadog-agent/conf.d/openmetrics.d/
# RUN cat /etc/hosts
# RUN service datadog-agent start

RUN go get ./...
RUN go build github.com/ChainSafe/gossamer/cmd/gossamer

# RUN gossamer --key bob init
RUN ["sh", "-c", "gossamer --key=${key} init"]
# ENTRYPOINT gossamer --key=bob --bootnodes /ip4/10.5.0.2/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU --rpc --rpc-external=true
ENTRYPOINT ["sh", "-c", "gossamer --key=${key} --bootnodes=/ip4/10.5.0.2/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU --rpc --rpc-external=true"]

EXPOSE 7001 8545 8546 8540 9876
59 changes: 59 additions & 0 deletions .devnet/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
services:
alice:
build:
context: ./..
dockerfile: alice.Dockerfile
ports:
- "7001"
- "8545"
- "8546"
- "8540"
- "9876"
networks:
vpcbr:
ipv4_address: 10.5.0.2

bob:
build:
context: ./..
dockerfile: bob.Dockerfile
args:
key: "bob"
ports:
- "7001"
- "8545"
- "8546"
- "8540"
- "9876"
networks:
vpcbr:
ipv4_address: 10.5.0.3
depends_on:
- "alice"

charlie:
build:
context: ./..
dockerfile: bob.Dockerfile
args:
key: "charlie"
ports:
- "7001"
- "8545"
- "8546"
- "8540"
- "9876"
networks:
vpcbr:
ipv4_address: 10.5.0.4
depends_on:
- "alice"

networks:
vpcbr:
driver: bridge
internal: true
ipam:
config:
- subnet: 10.5.0.0/16
gateway: 10.5.0.1
59 changes: 52 additions & 7 deletions dot/network/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,40 @@ type host struct {
closeSync sync.Once
}

func scanNetInterfaces() (ips []net.IP, err error) {
ifaces, err := net.Interfaces()
if err != nil {
return
}
for _, i := range ifaces {
var addrs []net.Addr
addrs, err = i.Addrs()
if err != nil {
return
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
default:
// don't know all the types that addr can be, continue to be safe
continue
}
if ip == nil || ip.IsUnspecified() || ip.IsLoopback() {
continue
}
if ip.To4() == nil {
continue
}
ips = append(ips, ip)
}
}
return
}

// newHost creates a host wrapper with a new libp2p host instance
func newHost(ctx context.Context, cfg *Config) (*host, error) {
// create multiaddress (without p2p identity)
Expand All @@ -73,16 +107,29 @@ func newHost(ctx context.Context, cfg *Config) (*host, error) {
return nil, err
}

var externalAddr ma.Multiaddr
var externalAddrs []ma.Multiaddr
ip, err := pubip.Get()
if err != nil {
logger.Error("failed to get public IP", "error", err)
// use local interface ip addresses as externalAddrs, this is used in the local devnet
ips, err := scanNetInterfaces()
if err != nil {
return nil, err
}
for _, ip := range ips {
externalAddr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", ip, cfg.Port))
if err != nil {
return nil, err
}
externalAddrs = append(externalAddrs, externalAddr)
}
} else {
logger.Debug("got public IP", "IP", ip)
externalAddr, err = ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", ip, cfg.Port))
logger.Info("got public IP", "IP", ip)
externalAddr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", ip, cfg.Port))
if err != nil {
return nil, err
}
externalAddrs = append(externalAddrs, externalAddr)
}

// create connection manager
Expand Down Expand Up @@ -118,7 +165,6 @@ func newHost(ctx context.Context, cfg *Config) (*host, error) {
if err != nil {
return nil, err
}

privateIPs.AddFilter(*ipnet, ma.ActionDeny)
}

Expand All @@ -142,11 +188,10 @@ func newHost(ctx context.Context, cfg *Config) (*host, error) {
addrs = append(addrs, addr)
}
}
if externalAddr == nil {
if externalAddrs == nil {
return addrs
}

return append(addrs, externalAddr)
return append(addrs, externalAddrs...)
}),
}

Expand Down

0 comments on commit 50ead6a

Please sign in to comment.