This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename example to cmd, move to a single .go file
- Loading branch information
1 parent
66081aa
commit c60ecae
Showing
5 changed files
with
69 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
Run | ||
```bash | ||
go run example/server/main.go | ||
go run cmd/tlsdiag.go server | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/libp2p/go-libp2p-tls/cmd/cmdimpl" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) <= 1 { | ||
fmt.Println("missing argument: client / server") | ||
return | ||
} | ||
|
||
role := os.Args[1] | ||
// remove the role argument from os.Args | ||
os.Args = append([]string{os.Args[0]}, os.Args[2:]...) | ||
|
||
var err error | ||
switch role { | ||
case "client": | ||
err = cmdimpl.StartClient() | ||
case "server": | ||
err = cmdimpl.StartServer() | ||
default: | ||
fmt.Println("invalid argument. Expected client / server") | ||
return | ||
} | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cmdimpl | ||
|
||
import ( | ||
"crypto/rand" | ||
"fmt" | ||
|
||
ic "github.com/libp2p/go-libp2p-crypto" | ||
) | ||
|
||
func generateKey(keyType string) (priv ic.PrivKey, err error) { | ||
switch keyType { | ||
case "rsa": | ||
fmt.Printf("Generated new peer with an RSA key.") | ||
priv, _, err = ic.GenerateRSAKeyPair(2048, rand.Reader) | ||
case "ecdsa": | ||
fmt.Printf("Generated new peer with an ECDSA key.") | ||
priv, _, err = ic.GenerateECDSAKeyPair(rand.Reader) | ||
case "ed25519": | ||
fmt.Printf("Generated new peer with an Ed25519 key.") | ||
priv, _, err = ic.GenerateEd25519Key(rand.Reader) | ||
case "secp256k1": | ||
fmt.Printf("Generated new peer with an Secp256k1 key.") | ||
priv, _, err = ic.GenerateSecp256k1Key(rand.Reader) | ||
default: | ||
return nil, fmt.Errorf("unknown key type: %s", keyType) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters