mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
delete more legacy documents
This commit is contained in:
parent
334cdf0141
commit
763b3ef0bc
3 changed files with 0 additions and 292 deletions
|
|
@ -1,161 +0,0 @@
|
|||
---
|
||||
title: Peer-to-peer
|
||||
---
|
||||
The peer to peer package ([go-ethereum/p2p](https://github.com/ethereum/go-ethereum/tree/master/p2p)) allows you to rapidly and easily add peer to peer networking to any type of application. The p2p package is set up in a modular structure and extending the p2p with your own additional sub protocols is easy and straight forward.
|
||||
|
||||
Starting the p2p service only requires you setup a `p2p.Server{}` with a few settings:
|
||||
|
||||
```go
|
||||
import "github.com/ethereum/go-ethereum/crypto"
|
||||
import "github.com/ethereum/go-ethereum/p2p"
|
||||
|
||||
nodekey, _ := crypto.GenerateKey()
|
||||
srv := p2p.Server{
|
||||
MaxPeers: 10,
|
||||
PrivateKey: nodekey,
|
||||
Name: "my node name",
|
||||
ListenAddr: ":30300",
|
||||
Protocols: []p2p.Protocol{},
|
||||
}
|
||||
srv.Start()
|
||||
```
|
||||
|
||||
If we wanted to extend the capabilities of our p2p server we'd need to pass it an additional sub protocol in the `Protocol: []p2p.Protocol{}` array.
|
||||
|
||||
An additional sub protocol that has the ability to respond to the message "foo" with "bar" requires you to setup an `p2p.Protocol{}`:
|
||||
|
||||
```go
|
||||
func MyProtocol() p2p.Protocol {
|
||||
return p2p.Protocol{ // 1.
|
||||
Name: "MyProtocol", // 2.
|
||||
Version: 1, // 3.
|
||||
Length: 1, // 4.
|
||||
Run: func(peer *p2p.Peer, ws p2p.MsgReadWriter) error { return nil }, // 5.
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
1. A sub-protocol object in the p2p package is called `Protocol{}`. Each time a peer connects with the capability of handling this type of protocol will use this;
|
||||
2. The name of your protocol to identify the protocol on the network;
|
||||
3. The version of the protocol.
|
||||
4. The amount of messages this protocol relies on. Because the p2p is extendible and thus has the ability to send an arbitrary amount of messages (with a type, which we'll see later) the p2p handler needs to know how much space it needs to reserve for your protocol, this to ensure consensus can be reached between the peers doing a negotiation over the message IDs. Our protocol supports only one; `message` (as you'll see later).
|
||||
5. The main handler of your protocol. We've left this intentionally blank for now. The `peer` variable is the peer connected to you and provides you with some basic information regarding the peer. The `ws` variable which is a reader and a writer allows you to communicate with the peer. If a message is being send to us by that peer the `MsgReadWriter` will handle it and vice versa.
|
||||
|
||||
Lets fill in the blanks and create a somewhat useful peer by allowing it to communicate with another peer:
|
||||
|
||||
```go
|
||||
const messageId = 0 // 1.
|
||||
type Message string // 2.
|
||||
|
||||
func msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error {
|
||||
for {
|
||||
msg, err := ws.ReadMsg() // 3.
|
||||
if err != nil { // 4.
|
||||
return err // if reading fails return err which will disconnect the peer.
|
||||
}
|
||||
|
||||
var myMessage [1]Message
|
||||
err = msg.Decode(&myMessage) // 5.
|
||||
if err != nil {
|
||||
// handle decode error
|
||||
continue
|
||||
}
|
||||
|
||||
switch myMessage[0] {
|
||||
case "foo":
|
||||
err := p2p.SendItems(ws, messageId, "bar") // 6.
|
||||
if err != nil {
|
||||
return err // return (and disconnect) error if writing fails.
|
||||
}
|
||||
default:
|
||||
fmt.Println("recv:", myMessage)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
1. The one and only message we know about;
|
||||
2. A typed string we decode in to;
|
||||
3. `ReadMsg` waits on the line until it receives a message, an error or EOF.
|
||||
4. In case of an error during reading it's best to return that error and let the p2p server handle it. This usually results in a disconnect from the peer.
|
||||
5. `msg` contains two fields and a decoding method:
|
||||
* `Code` contains the message id, `Code == messageId` (i.e., 0)
|
||||
* `Payload` the contents of the message.
|
||||
* `Decode(<ptr>)` is a helper method for: take `msg.Payload` and decodes the rest of the message in to the given interface. If it fails it will return an error.
|
||||
6. If the message we decoded was `foo` respond with a `NewMessage` using the `messageId` message identifier and respond with the message `bar`. The `bar` message would be handled in the `default` case in the same switch.
|
||||
|
||||
Now if we'd tie this all up we'd have a working p2p server with a message passing sub protocol.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
)
|
||||
|
||||
const messageId = 0
|
||||
|
||||
type Message string
|
||||
|
||||
func MyProtocol() p2p.Protocol {
|
||||
return p2p.Protocol{
|
||||
Name: "MyProtocol",
|
||||
Version: 1,
|
||||
Length: 1,
|
||||
Run: msgHandler,
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
nodekey, _ := crypto.GenerateKey()
|
||||
srv := p2p.Server{
|
||||
MaxPeers: 10,
|
||||
PrivateKey: nodekey,
|
||||
Name: "my node name",
|
||||
ListenAddr: ":30300",
|
||||
Protocols: []p2p.Protocol{MyProtocol()},
|
||||
}
|
||||
|
||||
if err := srv.Start(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
select {}
|
||||
}
|
||||
|
||||
func msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error {
|
||||
for {
|
||||
msg, err := ws.ReadMsg()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var myMessage Message
|
||||
err = msg.Decode(&myMessage)
|
||||
if err != nil {
|
||||
// handle decode error
|
||||
continue
|
||||
}
|
||||
|
||||
switch myMessage {
|
||||
case "foo":
|
||||
err := p2p.SendItems(ws, messageId, "bar"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
fmt.Println("recv:", myMessage)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
---
|
||||
title: Accounts
|
||||
---
|
||||
**THIS PAGE IS PARTLY OUTDATED! TODO: REFACTOR OR DELETE**
|
||||
|
||||
# Accounts / key storage specification
|
||||
|
||||
This is an attempt to compile a single, written specification from the multiple sources which have so far been used for accounts / key storage specs:
|
||||
|
||||
* Skype calls
|
||||
* Skype chats
|
||||
* Email conversations
|
||||
* Github issues
|
||||
* Github pull request comments
|
||||
* Github commits
|
||||
* Lively in-person discussions in the Amsterdam office.
|
||||
* Several past instances of the Amsterdam office whiteboard contents.
|
||||
|
||||
# Background
|
||||
|
||||
Up until Ethereum PoC 8, the Go client has used a single, default key in plaintext on disk for use as wallet and for signing all txs. We want to extend this to have a more generic key storage supporting multiple keys. We also want an "accounts" abstraction over these keys where an account corresponds to a key, and a user can have multiple accounts and be able to send / receive to any of them.
|
||||
|
||||
The goal of this is to support better wallet / account functionality both in Mist as well as in DAPPs.
|
||||
|
||||
# Specification
|
||||
|
||||
## Key Storage
|
||||
|
||||
The key storage must support:
|
||||
|
||||
1. Generation of new keys
|
||||
2. Deletion of keys.
|
||||
3. Multiple, uniquely identifiable keys.
|
||||
4. Password protection of keys.
|
||||
5. Persistence of keys (e.g. on disk)
|
||||
6. Export & Import of keys.
|
||||
7. Import of pre-sale keys (generated by https://github.com/ethereum/pyethsaletool) NOTE: this is a different import functionality than general import (6)
|
||||
8. Proper use of secure cryptography for key generation, password protection, key persistence and export format of keys.
|
||||
9. Mechanism for Backing the keys up – maybe automatically
|
||||
|
||||
## Account Manager
|
||||
|
||||
0. Account == address of an Ethereum account == address of EC public key of EC private key the user controls.
|
||||
|
||||
The account manager must support:
|
||||
|
||||
1. Account creation & deletion
|
||||
2. Multiple, unique accounts.
|
||||
3. Persistence of accounts (e.g. on disk)
|
||||
4. An account is mapped to a single key.
|
||||
5. The account is identifiable by some public, non-sensitive data. E.g. the Ethereum address of a EC keypair can be used as account identifier / address.
|
||||
|
||||
## Mist
|
||||
|
||||
The Mist UI must support:
|
||||
|
||||
1. Creation of a new account.
|
||||
2. Display a list of all available accounts (addresses)
|
||||
3. Copy-paste of account addresses to easily use when receiving funds.
|
||||
4. Choosing one of the available accounts when sending a tx.
|
||||
5. Typing password when accessing one of the hot wallet keys
|
||||
6. Showing the possible ways to temporarily input wallet keys when needed
|
||||
|
||||
## RPC API
|
||||
|
||||
The RPC API must support:
|
||||
|
||||
1. The list of accounts is exposed through the eth_accounts API: https://github.com/ethereum/wiki/JSON-RPC#eth_accounts
|
||||
2. Using any of the available accounts as from/sender with the eth_transact API: https://github.com/ethereum/wiki/JSON-RPC#eth_transact (NOTE: the current API definition on that wiki page does not include a from/sender field!)
|
||||
|
||||
|
||||
## Wallet DAPP
|
||||
|
||||
TODO:
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
---
|
||||
title: Setting up monitoring on local cluster
|
||||
---
|
||||
This page describes how to set up a monitoring site for your private network. It builds upon [this page](setting-up-private-network-or-local-cluster) and assumes you've created a local cluster using [this script (gethcluster.sh)](https://github.com/ethersphere/eth-utils).
|
||||
|
||||
The monitoring system consists of two components:
|
||||
|
||||
1. **eth-netstats** - the monitoring site which lists the nodes.
|
||||
2. **eth-net-intelligence-api** - these are processes that communicate with the ethereum client using RPC and push the data to the monitoring site via websockets.
|
||||
|
||||
#Monitoring site
|
||||
Clone the repo and install dependencies:
|
||||
|
||||
git clone https://github.com/cubedro/eth-netstats
|
||||
cd eth-netstats
|
||||
npm install
|
||||
|
||||
Then choose a secret and start the app:
|
||||
|
||||
WS_SECRET=<chosen_secret> npm start
|
||||
|
||||
You can now access the (empty) monitoring site at `http://localhost:3000`.
|
||||
|
||||
You can also choose a different port:
|
||||
|
||||
PORT=<chosen_port> WS_SECRET=<chosen_secret> npm start
|
||||
|
||||
#Client-side information relays
|
||||
These processes will relay the information from each of your cluster nodes to the monitoring site using websockets.
|
||||
|
||||
Clone the repo, install dependencies and make sure you have pm2 installed:
|
||||
|
||||
git clone https://github.com/cubedro/eth-net-intelligence-api
|
||||
cd eth-net-intelligence-api
|
||||
npm install
|
||||
sudo npm install -g pm2
|
||||
|
||||
Now, use [this script (netstatconf.sh)](https://github.com/ethersphere/eth-utils) to create an `app.json` suitable for pm2.
|
||||
|
||||
Usage:
|
||||
|
||||
bash netstatconf.sh <number_of_clusters> <name_prefix> <ws_server> <ws_secret>
|
||||
|
||||
- `number_of_clusters` is the number of nodes in the cluster.
|
||||
- `name_prefix` is a prefix for the node names as will appear in the listing.
|
||||
- `ws_server` is the eth-netstats server. Make sure you write the full URL, for example: http://localhost:3000.
|
||||
- `ws_secret` is the eth-netstats secret.
|
||||
|
||||
For example:
|
||||
|
||||
bash netstatconf.sh 5 mynode http://localhost:3000 big-secret > app.json
|
||||
|
||||
Run the script and copy the resulting `app.json` into the `eth-net-intelligence-api` directory. Afterwards, `cd` into `eth-net-intelligence-api` and run the relays using `pm2 start app.json`. To stop the relays, you can use `pm2 delete app.json`.
|
||||
|
||||
**NOTE**: The script assumes the nodes have RPC ports 8101, 8102, ... . If that's not the case, edit app.json and change it accordingly for each peer.
|
||||
|
||||
At this point, open `http://localhost:3000` and your monitoring site should monitor all your nodes!
|
||||
Loading…
Reference in a new issue