Skip to content

Commit

Permalink
Merge pull request #978 from subutai-io/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
crioto authored May 30, 2018
2 parents 95cb035 + 7f08a22 commit 98257a9
Show file tree
Hide file tree
Showing 22 changed files with 295 additions and 590 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* `show` command now accepts `--mtu` option to display current MTU VALUE
* Debian package now delivers /etc/default/subutai-p2p file with default P2P MTU VALUE
* Default P2P MTU value was changed to 1500 from 1376
* PMTU can be enabled by specifying `--pmtu` option for daemon command

## [7.0.0] 05/09/2018

Expand Down
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,20 @@ clean:
-rm -f $(NAME_PREFIX).exe
-rm -f $(NAME_PREFIX)-$(OS)*
-rm -rf debian/extra-code/*
-rm protocol/*.go

mrproper: clean
mrproper:
-rm -rf bin
-rm -f config.make

test:
go test -v ./...
go test -v github.com/subutai-io/p2p
go test -v github.com/subutai-io/p2p/lib
go test --bench . ./...

coverage:
go test -coverprofile=main.out -covermode=atomic
go test -coverprofile=lib.out -covermode=atomic github.com/subutai-io/p2p/lib
cat main.out > coverage.txt
cat lib.out >> coverage.txt
go test -coverprofile=coverage.txt -covermode=atomic github.com/subutai-io/p2p/lib

release: build
release:
Expand All @@ -97,3 +96,6 @@ snapcraft: $(SOURCES) service_posix.go
$(CC) get -d
$(CC) get -u github.com/golang/protobuf/proto
$(CC) build -ldflags="-r /apps/subutai/current/lib -w -s -X main.AppVersion=$(VERSION)$(BRANCH_POSTFIX) -X main.DefaultDHT=$(SNAPDHT) -X main.BuildID=$(BUILD) -X main.DefaultLog=$(LOG_LEVEL)" -o $(APP) -v $^

proto:
protoc --go_out=import_path=protocol:. protocol/dht.proto
4 changes: 3 additions & 1 deletion daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ type DaemonArgs struct {
}

var bootstrap DHTConnection
var UsePMTU bool

// ExecDaemon starts P2P daemon
func ExecDaemon(port int, dht, sFile, profiling, syslog, logLevel string, mtu int) {
func ExecDaemon(port int, dht, sFile, profiling, syslog, logLevel string, mtu int, pmtu bool) {
if logLevel == "" {
ptp.SetMinLogLevelString(DefaultLog)
} else {
Expand All @@ -56,6 +57,7 @@ func ExecDaemon(port int, dht, sFile, profiling, syslog, logLevel string, mtu in
StartProfiling(profiling)
ptp.InitPlatform()
ptp.InitErrors()
ptp.UsePMTU = pmtu

if !ptp.CheckPermissions() {
os.Exit(1)
Expand Down
5 changes: 5 additions & 0 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func (p *Daemon) Debug(args *Args, resp *Response) error {
resp.Output = fmt.Sprintf("Version: %s Build: %s\n", AppVersion, BuildID)
resp.Output += fmt.Sprintf("Uptime: %d h %d m %d s\n", int(time.Since(StartTime).Hours()), int(time.Since(StartTime).Minutes())%60, int(time.Since(StartTime).Seconds())%60)
resp.Output += fmt.Sprintf("Number of gouroutines: %d\n", runtime.NumGoroutine())
if ptp.UsePMTU {
resp.Output += fmt.Sprintf("PMTU: Enabled\n")
} else {
resp.Output += fmt.Sprintf("PMTU: Disabled\n")
}
resp.Output += fmt.Sprintf("Bootstrap nodes information:\n")
for _, node := range bootstrap.routers {
if node != nil {
Expand Down
27 changes: 14 additions & 13 deletions dht_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/golang/protobuf/proto"
ptp "github.com/subutai-io/p2p/lib"
"github.com/subutai-io/p2p/protocol"
)

// DHT Errors
Expand All @@ -19,19 +20,19 @@ var (

// DHTConnection to a DHT bootstrap node
type DHTConnection struct {
routers []*DHTRouter // Routers
routersList string // Comma-separated list of routers
lock sync.Mutex // Mutex for register/unregister
instances map[string]*P2PInstance // Instances
registered []string // List of registered swarm IDs
incoming chan *ptp.DHTPacket // Packets received by routers
ip string // Our outbound IP
isActive bool // Whether DHT connection is active or not
routers []*DHTRouter // Routers
routersList string // Comma-separated list of routers
lock sync.Mutex // Mutex for register/unregister
instances map[string]*P2PInstance // Instances
registered []string // List of registered swarm IDs
incoming chan *protocol.DHTPacket // Packets received by routers
ip string // Our outbound IP
isActive bool // Whether DHT connection is active or not
}

func (dht *DHTConnection) init(routersSrc string) error {
ptp.Log(ptp.Info, "Initializing connection to a bootstrap nodes")
dht.incoming = make(chan *ptp.DHTPacket)
dht.incoming = make(chan *protocol.DHTPacket)
routers := strings.Split(routersSrc, ",")
if len(routers) == 0 {
return ErrorNoRouters
Expand Down Expand Up @@ -79,8 +80,8 @@ func (dht *DHTConnection) registerInstance(hash string, inst *P2PInstance) error
}
dht.instances[hash] = inst
dht.registered = append(dht.registered, hash)
inst.PTP.Dht.IncomingData = make(chan *ptp.DHTPacket)
inst.PTP.Dht.OutgoingData = make(chan *ptp.DHTPacket)
inst.PTP.Dht.IncomingData = make(chan *protocol.DHTPacket)
inst.PTP.Dht.OutgoingData = make(chan *protocol.DHTPacket)
go func() {
for {
packet := <-inst.PTP.Dht.OutgoingData
Expand All @@ -94,7 +95,7 @@ func (dht *DHTConnection) registerInstance(hash string, inst *P2PInstance) error
return nil
}

func (dht *DHTConnection) send(packet *ptp.DHTPacket) {
func (dht *DHTConnection) send(packet *protocol.DHTPacket) {
if packet == nil {
return
}
Expand Down Expand Up @@ -126,7 +127,7 @@ func (dht *DHTConnection) run() {
}
ptp.Log(ptp.Trace, "Routing DHT Packet %+v", packet)
// Ping should always provide us with outbound IP value
if packet.Type == ptp.DHTPacketType_Ping && packet.Data != "" {
if packet.Type == protocol.DHTPacketType_Ping && packet.Data != "" {
dht.ip = packet.Data
continue
}
Expand Down
11 changes: 6 additions & 5 deletions dht_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/golang/protobuf/proto"
ptp "github.com/subutai-io/p2p/lib"
"github.com/subutai-io/p2p/protocol"
)

// DHTRouter represents a connection to a router
Expand All @@ -21,7 +22,7 @@ type DHTRouter struct {
fails int // Number of connection fails
tx uint64
rx uint64
data chan *ptp.DHTPacket
data chan *protocol.DHTPacket
lastContact time.Time
}

Expand Down Expand Up @@ -75,7 +76,7 @@ func (dht *DHTRouter) handleData(data []byte) {
}

func (dht *DHTRouter) routeData(data []byte) {
packet := &ptp.DHTPacket{}
packet := &protocol.DHTPacket{}
err := proto.Unmarshal(data, packet)
ptp.Log(ptp.Trace, "DHTPacket size: [%d]", len(data))
ptp.Log(ptp.Trace, "DHTPacket contains: %+v --- %+v", bytes.NewBuffer(data).String(), packet)
Expand All @@ -84,7 +85,7 @@ func (dht *DHTRouter) routeData(data []byte) {
return
}
ptp.Log(ptp.Trace, "Received DHT packet: %+v", packet)
if packet.Type == ptp.DHTPacketType_Ping && dht.handshaked == false {
if packet.Type == protocol.DHTPacketType_Ping && dht.handshaked == false {
supported := false
for _, v := range ptp.SupportedVersion {
if v == packet.Version {
Expand Down Expand Up @@ -175,8 +176,8 @@ func (dht *DHTRouter) sendRaw(data []byte) (int, error) {

func (dht *DHTRouter) ping() error {
ptp.Log(ptp.Trace, "Sending ping to dht %s", dht.addr.String())
packet := &ptp.DHTPacket{
Type: ptp.DHTPacketType_Ping,
packet := &protocol.DHTPacket{
Type: protocol.DHTPacketType_Ping,
Query: "req",
Version: ptp.PacketVersion,
}
Expand Down
13 changes: 7 additions & 6 deletions dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/golang/protobuf/proto"
ptp "github.com/subutai-io/p2p/lib"
"github.com/subutai-io/p2p/protocol"
)

func TestRouteData(t *testing.T) {
Expand All @@ -17,13 +18,13 @@ func TestRouteData(t *testing.T) {
i++
}

data := []ptp.DHTPacket{
ptp.DHTPacket{},
ptp.DHTPacket{
Type: ptp.DHTPacketType_Ping,
data := []protocol.DHTPacket{
protocol.DHTPacket{},
protocol.DHTPacket{
Type: protocol.DHTPacketType_Ping,
},
ptp.DHTPacket{
Type: ptp.DHTPacketType_Ping,
protocol.DHTPacket{
Type: protocol.DHTPacketType_Ping,
Arguments: dataArr,
},
}
Expand Down
Loading

0 comments on commit 98257a9

Please sign in to comment.