Browse Source

基本逻辑结构确立

skyfffire 2 years ago
parent
commit
84e145b902
2 changed files with 22 additions and 2 deletions
  1. 12 0
      cmd/p2p/main.go
  2. 10 2
      p2p/server.go

+ 12 - 0
cmd/p2p/main.go

@@ -0,0 +1,12 @@
+package main
+
+import "blockchain-go/p2p"
+
+func main() {
+	server := &p2p.Server{}
+
+	err := server.Start()
+	if err != nil {
+		return
+	}
+}

+ 10 - 2
p2p/server.go

@@ -2,6 +2,8 @@ package p2p
 
 import (
 	"errors"
+	"fmt"
+	"sync"
 )
 
 var (
@@ -19,8 +21,8 @@ type Server struct {
 	//newPeerHook  func(*Peer)
 	//listenFunc func(network, addr string) (net.Listener, error)
 
-	//lock    sync.Mutex // protects running
-	//running bool
+	lock    sync.Mutex // protects running
+	running bool
 
 	//listener net.Listener
 	//ourHandshake *protoHandshake
@@ -48,3 +50,9 @@ type Server struct {
 	// State of run loop and listenLoop.
 	//inboundHistory expHeap
 }
+
+func (srv *Server) Start() (err error) {
+	fmt.Println("Hello World.")
+
+	return nil
+}