Skip to content

Commit

Permalink
Move Config and ACL to the top-level module (libp2p#20)
Browse files Browse the repository at this point in the history
I would like to programatically generate relays configurations, however this
is slightly more difficult because, despite being exported types, they are in
the "main" package.

This PR moves them to the top-level directory so that they can be imported from
other modules.

I also took the liberty of documenting things.
  • Loading branch information
hsanjuan authored and TheDiscordian committed Oct 4, 2022
1 parent 0ce42f2 commit c81878a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type TLSConfig struct {
KeyPairPaths [][2]string
}

// DefaultConfig returns a default relay configuration using default resource
// settings and no ACLs.
func DefaultConfig() Config {
return Config{
Network: NetworkConfig{
Expand Down
7 changes: 4 additions & 3 deletions identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package relaydaemon

import (
"fmt"
"io/ioutil"
"os"

"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p-core/crypto"
)

// LoadIdentity reads a private key from the given path and, if it does not
Expand All @@ -22,7 +23,7 @@ func LoadIdentity(idPath string) (crypto.PrivKey, error) {

// ReadIdentity reads a private key from the given path.
func ReadIdentity(path string) (crypto.PrivKey, error) {
bytes, err := os.ReadFile(path)
bytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
Expand All @@ -42,7 +43,7 @@ func GenerateIdentity(path string) (crypto.PrivKey, error) {
return nil, err
}

err = os.WriteFile(path, bytes, 0400)
err = ioutil.WriteFile(path, bytes, 0400)

return privk, err
}

0 comments on commit c81878a

Please sign in to comment.