|
|
@@ -1,9 +1,32 @@
|
|
|
package p2p
|
|
|
|
|
|
-import "net"
|
|
|
+import (
|
|
|
+ "blockchain-go/p2p/enode"
|
|
|
+ "net"
|
|
|
+)
|
|
|
|
|
|
type connFlag int32
|
|
|
|
|
|
+func (f connFlag) String() string {
|
|
|
+ s := ""
|
|
|
+ if f&trustedConn != 0 {
|
|
|
+ s += "-trusted"
|
|
|
+ }
|
|
|
+ if f&dynDialedConn != 0 {
|
|
|
+ s += "-dyndial"
|
|
|
+ }
|
|
|
+ if f&staticDialedConn != 0 {
|
|
|
+ s += "-staticdial"
|
|
|
+ }
|
|
|
+ if f&inboundConn != 0 {
|
|
|
+ s += "-inbound"
|
|
|
+ }
|
|
|
+ if s != "" {
|
|
|
+ s = s[1:]
|
|
|
+ }
|
|
|
+ return s
|
|
|
+}
|
|
|
+
|
|
|
const (
|
|
|
dynDialedConn connFlag = 1 << iota
|
|
|
staticDialedConn
|
|
|
@@ -15,19 +38,19 @@ const (
|
|
|
// during the two handshakes.
|
|
|
type conn struct {
|
|
|
fd net.Conn
|
|
|
- //transport
|
|
|
- //node *enode.Node
|
|
|
+ transport
|
|
|
+ node *enode.Node
|
|
|
flags connFlag
|
|
|
cont chan error // The run loop uses cont to signal errors to SetupConn.
|
|
|
- //caps []Cap // valid after the protocol handshake
|
|
|
- name string // valid after the protocol handshake
|
|
|
+ caps []Cap // valid after the protocol handshake
|
|
|
+ name string // valid after the protocol handshake
|
|
|
}
|
|
|
|
|
|
-//func (c *conn) String() string {
|
|
|
-// s := c.flags.String()
|
|
|
-// if (c.node.ID() != enode.ID{}) {
|
|
|
-// s += " " + c.node.ID().String()
|
|
|
-// }
|
|
|
-// s += " " + c.fd.RemoteAddr().String()
|
|
|
-// return s
|
|
|
-//}
|
|
|
+func (c *conn) String() string {
|
|
|
+ s := c.flags.String()
|
|
|
+ if (c.node.ID() != enode.ID{}) {
|
|
|
+ s += " " + c.node.ID().String()
|
|
|
+ }
|
|
|
+ s += " " + c.fd.RemoteAddr().String()
|
|
|
+ return s
|
|
|
+}
|