2019-05-09 12:18:12 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-05-13 20:59:59 +00:00
|
|
|
"os"
|
2019-05-09 12:18:12 +00:00
|
|
|
"reflect"
|
|
|
|
|
|
|
|
cluster "github.com/ipfs/ipfs-cluster"
|
|
|
|
)
|
|
|
|
|
|
|
|
func rpcTypeStr(t cluster.RPCEndpointType) string {
|
|
|
|
switch t {
|
|
|
|
case cluster.RPCClosed:
|
|
|
|
return "RPCClosed"
|
|
|
|
case cluster.RPCTrusted:
|
|
|
|
return "RPCTrusted"
|
|
|
|
case cluster.RPCOpen:
|
|
|
|
return "RPCOpen"
|
|
|
|
default:
|
|
|
|
return "ERROR"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-13 20:59:59 +00:00
|
|
|
var comments = map[string]string{
|
|
|
|
"Cluster.PeerAdd": "Used by Join()",
|
|
|
|
"Cluster.Peers": "Used by ConnectGraph()",
|
|
|
|
"Cluster.Pins": "Used in stateless tracker, ipfsproxy, restapi",
|
|
|
|
"Cluster.SyncAllLocal": "Called in broadcast from SyncAll()",
|
|
|
|
"Cluster.SyncLocal": "Called in broadcast from Sync()",
|
|
|
|
"PinTracker.Recover": "Called in broadcast from Recover()",
|
|
|
|
"PinTracker.RecoverAll": "Broadcast in RecoverAll unimplemented",
|
|
|
|
"Pintracker.Status": "Called in broadcast from Status()",
|
|
|
|
"Pintracker.StatusAll": "Called in broadcast from StatusAll()",
|
|
|
|
"IPFSConnector.BlockPut": "Called from Add()",
|
|
|
|
"IPFSConnector.RepoStat": "Called in broadcast from proxy/repo/stat",
|
|
|
|
"IPFSConnector.SwarmPeers": "Called in ConnectGraph",
|
|
|
|
"Consensus.AddPeer": "Called by Raft/redirect to leader",
|
|
|
|
"Consensus.LogPin": "Called by Raft/redirect to leader",
|
|
|
|
"Consensus.LogUnpin": "Called by Raft/redirect to leader",
|
|
|
|
"Consensus.RmPeer": "Called by Raft/redirect to leader",
|
|
|
|
}
|
|
|
|
|
2019-05-09 12:18:12 +00:00
|
|
|
func main() {
|
2019-05-09 14:33:59 +00:00
|
|
|
rpcComponents := []interface{}{
|
2019-05-09 12:18:12 +00:00
|
|
|
&cluster.ClusterRPCAPI{},
|
|
|
|
&cluster.PinTrackerRPCAPI{},
|
|
|
|
&cluster.IPFSConnectorRPCAPI{},
|
|
|
|
&cluster.ConsensusRPCAPI{},
|
|
|
|
&cluster.PeerMonitorRPCAPI{},
|
|
|
|
}
|
|
|
|
|
2019-05-13 20:59:59 +00:00
|
|
|
fmt.Fprintln(os.Stderr, `
|
2019-05-09 12:18:12 +00:00
|
|
|
// The below generated policy keeps the endpoint types
|
2019-05-13 20:59:59 +00:00
|
|
|
// from the exiting one, marking new endpoints as NEW. Redirect stdout
|
|
|
|
// into rpc_policy.go and set the NEW endpoints to their correct type (make
|
|
|
|
// sure you have recompiled this binary with the current version of the code).
|
|
|
|
============================================================================`)
|
|
|
|
fmt.Fprintln(os.Stderr)
|
2019-05-09 12:18:12 +00:00
|
|
|
|
2019-05-13 20:59:59 +00:00
|
|
|
fmt.Println("package ipfscluster")
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("// This file can be generated with rpcutil/policygen.")
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println(`
|
|
|
|
// DefaultRPCPolicy associates all rpc endpoints offered by cluster peers to an
|
|
|
|
// endpoint type. See rpcutil/policygen.go as a quick way to generate this
|
|
|
|
// without missing any endpoint.`)
|
|
|
|
fmt.Println("var DefaultRPCPolicy = map[string]RPCEndpointType{")
|
2019-05-09 12:18:12 +00:00
|
|
|
|
|
|
|
for _, c := range rpcComponents {
|
|
|
|
t := reflect.TypeOf(c)
|
|
|
|
|
2019-05-09 14:33:59 +00:00
|
|
|
fmt.Println(" //", cluster.RPCServiceID(c), "methods")
|
2019-05-09 12:18:12 +00:00
|
|
|
for i := 0; i < t.NumMethod(); i++ {
|
|
|
|
method := t.Method(i)
|
2019-05-13 20:59:59 +00:00
|
|
|
name := cluster.RPCServiceID(c) + "." + method.Name
|
2019-05-09 12:18:12 +00:00
|
|
|
rpcT, ok := cluster.DefaultRPCPolicy[name]
|
|
|
|
rpcTStr := "NEW"
|
|
|
|
if ok {
|
|
|
|
rpcTStr = rpcTypeStr(rpcT)
|
|
|
|
}
|
2019-05-13 20:59:59 +00:00
|
|
|
comment, ok := comments[name]
|
|
|
|
if ok {
|
|
|
|
comment = "// " + comment
|
|
|
|
}
|
2019-05-09 12:18:12 +00:00
|
|
|
|
2019-05-13 20:59:59 +00:00
|
|
|
fmt.Printf(" \"%s\": %s, %s\n", name, rpcTStr, comment)
|
2019-05-09 12:18:12 +00:00
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("}")
|
|
|
|
}
|