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 b14d827
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 63 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
56 changes: 0 additions & 56 deletions chain/gssmr/genesis-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,6 @@
[
"5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
1
],
[
"5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy",
1
],
[
"5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw",
1
],
[
"5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL",
1
],
[
"5DeWA2u2f8Bb1DXBEohUHWXW3NUzKNg75jYSHaEZWKdE6ZuR",
1
],
[
"5GMykc9TjNsmDftompy44gdWtJHnHxZ5wo7h7mJRKdowjz4z",
1
],
[
"5CULg8vw1SMeCsUHcXR6YZP43eMxjdMLqMriZZe5q9HA3V3c",
1
]
]
},
Expand All @@ -52,38 +28,6 @@
[
"5DFNv4Txc4b88qHqQ6GG4D646QcT4fN3jjS2G3r1PyZkfDut",
1
],
[
"5FRbF5E5xpBxaCdjuVkCAtoLgvvoL6wJoE7kAVTUdZBwpgi7",
1
],
[
"5DYo8CvjQcBQFdehVhansDiZCPebpgqvNC8PQPi6K9cL9giT",
1
],
[
"5EtkA16QN4DED9vrxb4LnmytCFBhm6qJ5pw6FkoaiRtsPeuG",
1
],
[
"5G64P3LJTK28dDVGNSzSHp4mfZyKqdzxgeZ1cULRoxMdt8m1",
1
],
[
"5D7QrtMByWQpi8EtqkH1sPDBCVZvoH6G1vY5mknQiCC3ZVQM",
1
],
[
"5FdsD3mYg5gzh1Uj4FxyeHqMTpaAVd3gDNmcuKypBzRGGMQH",
1
],
[
"5DqDws3YxzL8r741gw33jdbohzAESRR9qGCGg6GAZ3Qw5fYX",
1
],
[
"5FYrfAUUzuahCL2swxoPXc846dKrWuD2nwzrKc1oEfWBS6RL",
1
]
]
},
Expand Down
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 b14d827

Please sign in to comment.