From e0bee6fef5291b192a46af37419572396dae69b4 Mon Sep 17 00:00:00 2001 From: Christian Mouchet Date: Wed, 17 Apr 2024 15:22:52 +0200 Subject: [PATCH] adding some godoc --- api/messages.go | 1 + coordinator/coordinator.go | 3 ++ helium.go | 2 + node/localtest.go | 25 --------- node/node.go | 103 ------------------------------------- node/transport.go | 2 - stats.go | 52 +++++++++++++++++++ 7 files changed, 58 insertions(+), 130 deletions(-) diff --git a/api/messages.go b/api/messages.go index 90e8397..31e8972 100644 --- a/api/messages.go +++ b/api/messages.go @@ -1,3 +1,4 @@ +// Package api implements a translation layer between the protobuf and internal Helium types. package api import ( diff --git a/coordinator/coordinator.go b/coordinator/coordinator.go index 21d4971..31031cd 100644 --- a/coordinator/coordinator.go +++ b/coordinator/coordinator.go @@ -1,3 +1,6 @@ +// Package coordinator implements a generic coordinator functionality for helium nodes. +// The coordinator orchestrates the execution of the MHE-based MPC protocol by executing +// its sub-protocols and routines. package coordinator import ( diff --git a/helium.go b/helium.go index ddca0fb..5bece47 100644 --- a/helium.go +++ b/helium.go @@ -1,3 +1,5 @@ +// Package helium is the main entrypoint to the Helium library. +// It provides function to configure and run a Helium helper server and Helium clients. package helium import ( diff --git a/node/localtest.go b/node/localtest.go index e160efe..5618cd1 100644 --- a/node/localtest.go +++ b/node/localtest.go @@ -323,31 +323,6 @@ func createTLSConfigs(testConfig LocalTestConfig, nodeList List) (map[session.No return tlsConfigs, nil } -const buffConBufferSize = 65 * 1024 * 1024 - -// Start creates some in-memory connections between the nodes and returns -// when all nodes are connected. -// func (lc LocalTest) Start() { -// lis := bufconn.Listen(buffConBufferSize) - -// go lc.HelperNode.srv.Server.Serve(lis) - -// var wg sync.WaitGroup -// for _, node := range lc.SessionNodes() { -// node := node -// wg.Add(1) -// go func() { -// err := node.cli.ConnectWithDialer(func(context.Context, string) (net.Conn, error) { return lis.Dial() }) -// if err != nil { -// log.Printf("node %s failed to connect: %v", node.ID(), err) -// return -// } -// wg.Done() -// }() -// } -// wg.Wait() -// } - // SessionNodes returns the set of nodes in the local test that are part of the // session. func (lc LocalTest) SessionNodes() []*Node { diff --git a/node/node.go b/node/node.go index 7cd89c9..0751d27 100644 --- a/node/node.go +++ b/node/node.go @@ -104,47 +104,6 @@ func New(config Config, nodeList List) (node *Node, err error) { return node, err } -// RunNew creates a new Helium node from the provided config and node list, and runs the node with the provided app under the given context. -func RunNew(ctx context.Context, config Config, nodeList List, app App, ip compute.InputProvider, upstream Coordinator, trans Transport) (node *Node, cdescs chan<- circuit.Descriptor, outs <-chan circuit.Output, err error) { - node, err = New(config, nodeList) - if err != nil { - return nil, nil, nil, err - } - - // err = node.Connect(ctx) - // if err != nil { - // return nil, nil, nil, err - // } - - cdescs, outs, err = node.Run(ctx, app, ip, upstream, trans) - return -} - -// Connect connects the node's transport layer to the network. -// If the node has an address, it starts a server at the address. -// If the node does not have an address, it connects to the helper node. -// func (node *Node) Connect(ctx context.Context) error { -// if node.HasAddress() { -// listener, err := net.Listen("tcp", string(node.addr)) -// if err != nil { -// return err -// } -// node.Logf("starting server at %s", node.addr) -// go func() { -// if err := node.srv.Server.Serve(listener); err != nil { -// log.Fatalf("error in grpc serve: %v", err) -// } -// }() -// } else { -// node.Logf("connecting to %s at %s", node.helperID, node.nodeList.AddressOf(node.helperID)) -// err := node.cli.Connect() -// if err != nil { -// return err -// } -// } -// return nil -// } - // Run runs the node with the provided app under the given context. // The method returns channels to send circuit descriptors and receive circuit outputs. // @@ -240,16 +199,6 @@ func (node *Node) Run(ctx context.Context, app App, ip compute.InputProvider, up return cds, or, nil } -// Close releases all the resources allocated by the node. -// If the node is the helper node, it stops the server and -// waits for the peers to disconnect. -// func (node *Node) Close() error { -// if node.IsHelperNode() { -// node.srv.Server.GracefulStop() -// } -// return nil -// } - // Transport interface implementation // GetAggregationOutput returns the aggregation output for a given protocol descriptor. @@ -344,58 +293,6 @@ func (node *Node) Logf(msg string, v ...any) { log.Printf("%s | [node] %s\n", node.id, fmt.Sprintf(msg, v...)) } -// func (node *Node) GetNetworkStats() centralized.NetStats { -// var stats, srvStats, cliStats centralized.NetStats -// if node.srv != nil { -// srvStats = node.srv.GetStats() -// stats.DataRecv += srvStats.DataRecv -// stats.DataSent += srvStats.DataSent -// } -// if node.cli != nil { -// cliStats = node.cli.GetStats() -// stats.DataRecv += cliStats.DataRecv -// stats.DataSent += cliStats.DataSent -// } -// return stats -// } - -// // outputStats outputs the total network usage and time take to execute a protocol phase. -// func (node *Node) OutputStats(phase string, elapsed time.Duration, write bool, metadata ...map[string]string) { - -// dataSent := node.GetTransport().GetNetworkStats().DataSent -// dataRecv := node.GetTransport().GetNetworkStats().DataRecv -// fmt.Printf("STATS: phase: %s time: %f sent: %f MB recv: %f MB\n", phase, elapsed.Seconds(), float64(dataSent)/float64(1e6), float64(dataRecv)/float64(1e6)) -// log.Println("==============", phase, "phase ==============") -// log.Printf("%s | time %s", node.ID(), elapsed) -// log.Printf("%s | network: %s\n", node.ID(), node.GetTransport().GetNetworkStats()) -// if write { -// stats := map[string]string{ -// "Wall": fmt.Sprint(elapsed), -// "Sent": fmt.Sprint(dataSent), -// "Recvt": fmt.Sprint(dataRecv), -// "ID": fmt.Sprint(node.ID()), -// "Phase": phase, -// } -// for _, md := range metadata { -// for k, v := range md { -// stats[k] = v -// } -// } -// var statsJSON []byte -// statsJSON, err := json.MarshalIndent(stats, "", "\t") -// if err != nil { -// panic(err) -// } -// if errWrite := os.WriteFile(fmt.Sprintf("/helium/stats/%s-%s.json", phase, node.ID()), statsJSON, 0600); errWrite != nil { -// log.Println(errWrite) -// } -// } -// } - -// func (node *Node) ResetNetworkStats() { -// node.transport.ResetNetworkStats() -// } - // func (node *Node) RegisterPostsetupHandler(h func(*pkg.SessionStore, compute.PublicKeyBackend) error) { // node.postsetupHandler = h // } diff --git a/node/transport.go b/node/transport.go index f4bee70..13b0793 100644 --- a/node/transport.go +++ b/node/transport.go @@ -102,8 +102,6 @@ type testTransport struct { helperSetupSrv *setup.Service helperCompSrv *compute.Service *protocol.TestTransport - - //clients []chan protocol.Share } func NewTestTransport(hid session.NodeID, helperSetupSrv *setup.Service, helperCompSrv *compute.Service) *testTransport { diff --git a/stats.go b/stats.go index 298d57a..8410cc1 100644 --- a/stats.go +++ b/stats.go @@ -64,3 +64,55 @@ func (s *statsHandler) GetStats() NetStats { defer s.mu.Unlock() return s.stats } + +// func (node *Node) GetNetworkStats() centralized.NetStats { +// var stats, srvStats, cliStats centralized.NetStats +// if node.srv != nil { +// srvStats = node.srv.GetStats() +// stats.DataRecv += srvStats.DataRecv +// stats.DataSent += srvStats.DataSent +// } +// if node.cli != nil { +// cliStats = node.cli.GetStats() +// stats.DataRecv += cliStats.DataRecv +// stats.DataSent += cliStats.DataSent +// } +// return stats +// } + +// // outputStats outputs the total network usage and time take to execute a protocol phase. +// func (node *Node) OutputStats(phase string, elapsed time.Duration, write bool, metadata ...map[string]string) { + +// dataSent := node.GetTransport().GetNetworkStats().DataSent +// dataRecv := node.GetTransport().GetNetworkStats().DataRecv +// fmt.Printf("STATS: phase: %s time: %f sent: %f MB recv: %f MB\n", phase, elapsed.Seconds(), float64(dataSent)/float64(1e6), float64(dataRecv)/float64(1e6)) +// log.Println("==============", phase, "phase ==============") +// log.Printf("%s | time %s", node.ID(), elapsed) +// log.Printf("%s | network: %s\n", node.ID(), node.GetTransport().GetNetworkStats()) +// if write { +// stats := map[string]string{ +// "Wall": fmt.Sprint(elapsed), +// "Sent": fmt.Sprint(dataSent), +// "Recvt": fmt.Sprint(dataRecv), +// "ID": fmt.Sprint(node.ID()), +// "Phase": phase, +// } +// for _, md := range metadata { +// for k, v := range md { +// stats[k] = v +// } +// } +// var statsJSON []byte +// statsJSON, err := json.MarshalIndent(stats, "", "\t") +// if err != nil { +// panic(err) +// } +// if errWrite := os.WriteFile(fmt.Sprintf("/helium/stats/%s-%s.json", phase, node.ID()), statsJSON, 0600); errWrite != nil { +// log.Println(errWrite) +// } +// } +// } + +// func (node *Node) ResetNetworkStats() { +// node.transport.ResetNetworkStats() +// }