@@ -8,17 +8,20 @@ import (
8
8
"path"
9
9
"sort"
10
10
"strings"
11
+ "time"
11
12
12
13
cmds "github.com/ipfs/go-ipfs/commands"
13
14
repo "github.com/ipfs/go-ipfs/repo"
14
15
config "github.com/ipfs/go-ipfs/repo/config"
15
16
"github.com/ipfs/go-ipfs/repo/fsrepo"
16
- pstore "gx/ipfs/QmPgDWmTmuzvP7QE5zwo1TmjbJme9pmZHNujB2453jkCTr/go-libp2p-peerstore"
17
- swarm "gx/ipfs/QmdQFrFnPrKRQtpeHKjZ3cVNwxmGKKS2TvhJTuN9C9yduh/go-libp2p-swarm"
18
- iaddr "gx/ipfs/QmeS8cCKawUwejVrsBtmC1toTXmwVWZGiRJqzgTURVWeF9/go-ipfs-addr"
19
17
18
+ pstore "gx/ipfs/QmPgDWmTmuzvP7QE5zwo1TmjbJme9pmZHNujB2453jkCTr/go-libp2p-peerstore"
20
19
mafilter "gx/ipfs/QmSMZwvs3n4GBikZ7hKzT17c3bk65FmyZo2JqtJ16swqCv/multiaddr-filter"
20
+ connmgr "gx/ipfs/QmUbUNq1Q6eE2LXqKzKW8BW1SUMqscAj9A3ot9j5suuaRb/go-libp2p-connmgr"
21
21
ma "gx/ipfs/QmXY77cVe7rVRQXZZQRioukUM7aRW3BTcAgJe12MCtb3Ji/go-multiaddr"
22
+ ifconnmgr "gx/ipfs/QmYkCrTwivapqdB3JbwvwvxymseahVkcm46ThRMAA24zCr/go-libp2p-interface-connmgr"
23
+ swarm "gx/ipfs/QmdQFrFnPrKRQtpeHKjZ3cVNwxmGKKS2TvhJTuN9C9yduh/go-libp2p-swarm"
24
+ iaddr "gx/ipfs/QmeS8cCKawUwejVrsBtmC1toTXmwVWZGiRJqzgTURVWeF9/go-ipfs-addr"
22
25
)
23
26
24
27
type stringList struct {
@@ -44,6 +47,7 @@ ipfs peers in the internet.
44
47
"disconnect" : swarmDisconnectCmd ,
45
48
"filters" : swarmFiltersCmd ,
46
49
"peers" : swarmPeersCmd ,
50
+ "connmgr" : swarmConnMgrCmd ,
47
51
},
48
52
}
49
53
@@ -812,3 +816,83 @@ func filtersRemove(r repo.Repo, cfg *config.Config, toRemoveFilters []string) ([
812
816
813
817
return removed , nil
814
818
}
819
+
820
+ var swarmConnMgrCmd = & cmds.Command {
821
+ Helptext : cmds.HelpText {
822
+ Tagline : "Interact with the Connection Manager." ,
823
+ ShortDescription : `
824
+ Display information about the current state of the connection manager.
825
+ ` ,
826
+ },
827
+ Run : func (req cmds.Request , res cmds.Response ) {
828
+ n , err := req .InvocContext ().GetNode ()
829
+ if err != nil {
830
+ res .SetError (err , cmds .ErrNormal )
831
+ return
832
+ }
833
+
834
+ if n .PeerHost == nil {
835
+ res .SetError (errNotOnline , cmds .ErrClient )
836
+ return
837
+ }
838
+
839
+ infos := make (map [string ]interface {})
840
+ cmgr := n .PeerHost .ConnManager ()
841
+ switch cmgr := cmgr .(type ) {
842
+ case nil :
843
+ infos ["type" ] = "<nil>"
844
+ case * ifconnmgr.NullConnMgr :
845
+ infos ["type" ] = "disabled"
846
+ case * connmgr.BasicConnMgr :
847
+ infos ["type" ] = "basic"
848
+
849
+ inf := cmgr .GetInfo ()
850
+ infos ["lowWater" ] = inf .LowWater
851
+ infos ["highWater" ] = inf .HighWater
852
+ infos ["lastTrim" ] = inf .LastTrim
853
+ infos ["gracePeriod" ] = inf .GracePeriod .String ()
854
+ infos ["connCount" ] = inf .ConnCount
855
+ default :
856
+ infos ["type" ] = "unknown"
857
+ }
858
+
859
+ res .SetOutput (infos )
860
+ },
861
+ Marshalers : cmds.MarshalerMap {
862
+ cmds .Text : func (res cmds.Response ) (io.Reader , error ) {
863
+ infosp , ok := res .Output ().(* map [string ]interface {})
864
+ if ! ok {
865
+ return nil , fmt .Errorf ("expected output type to be a map: %#v" , res .Output ())
866
+ }
867
+ infos := * infosp
868
+
869
+ buf := new (bytes.Buffer )
870
+
871
+ switch infos ["type" ] {
872
+ case "basic" :
873
+ tstr := "<n/a>"
874
+ t , err := time .Parse (time .RFC3339Nano , infos ["lastTrim" ].(string ))
875
+ if err != nil {
876
+ tstr = "<err>"
877
+ } else if ! t .IsZero () {
878
+ tstr = t .String ()
879
+ }
880
+
881
+ fmt .Fprintf (buf , "Type: basic\n " )
882
+ fmt .Fprintf (buf , "Low Water: %d\n " , int (infos ["lowWater" ].(float64 )))
883
+ fmt .Fprintf (buf , "High Water: %d\n " , int (infos ["highWater" ].(float64 )))
884
+ fmt .Fprintf (buf , "Grace Period: %s\n " , infos ["gracePeriod" ])
885
+ fmt .Fprintf (buf , "Connection Count: %d\n " , int (infos ["connCount" ].(float64 )))
886
+ fmt .Fprintf (buf , "Last Trim: %s\n " , tstr )
887
+ case "none" :
888
+ fmt .Println ("Connection Manager Disabled" )
889
+ default :
890
+ log .Errorf ("unknown connection manager type: %s" , infos ["type" ])
891
+ fmt .Println ("Unknown Connection Manager Settings" )
892
+ }
893
+
894
+ return buf , nil
895
+ },
896
+ },
897
+ Type : make (map [string ]interface {}),
898
+ }
0 commit comments