Skip to content

Commit

Permalink
More verbosity on debug
Browse files Browse the repository at this point in the history
  • Loading branch information
crioto committed Mar 2, 2018
1 parent 600f7c6 commit 2706c1a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 54 deletions.
2 changes: 2 additions & 0 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func (dht *DHTConnection) run() {
i, e := dht.instances[packet.Infohash]
if e {
i.PTP.Dht.IncomingData <- packet
} else {
ptp.Log(ptp.Debug, "DHT received data from unknown instance %s: %+v", packet.Infohash, packet)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (dht *DHTClient) Connect(ipList []net.IP, proxyList []*proxyServer) error {
}
// Waiting for 3 seconds to get connection confirmation
sent := time.Now()
for time.Since(sent) < time.Duration(3000*time.Millisecond) {
for time.Since(sent) < time.Duration(5000*time.Millisecond) {
if dht.Connected {
return nil
}
Expand Down
50 changes: 0 additions & 50 deletions lib/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,56 +159,6 @@ func (p *PeerToPeer) IsIPv4(ip string) bool {
return false
}

// FindNetworkAddresses method lists interfaces available in the system and retrieves their
// IP addresses
func (p *PeerToPeer) FindNetworkAddresses() {
Log(Debug, "Looking for available network interfaces")
inf, err := net.Interfaces()
if err != nil {
Log(Error, "Failed to retrieve list of network interfaces")
return
}
p.LocalIPs = p.LocalIPs[:0]
for _, i := range inf {
addresses, err := i.Addrs()

if err != nil {
Log(Error, "Failed to retrieve address for interface. %v", err)
continue
}
for _, addr := range addresses {
var decision = "Ignoring"
var ipType = "Unknown"
ip, _, err := net.ParseCIDR(addr.String())
if err != nil {
Log(Error, "Failed to parse CIDR notation: %v", err)
}
if ip.IsLoopback() {
ipType = "Loopback"
} else if ip.IsMulticast() {
ipType = "Multicast"
} else if ip.IsGlobalUnicast() {
decision = "Saving"
ipType = "Global Unicast"
} else if ip.IsLinkLocalUnicast() {
ipType = "Link Local Unicast"
} else if ip.IsLinkLocalMulticast() {
ipType = "Link Local Multicast"
} else if ip.IsInterfaceLocalMulticast() {
ipType = "Interface Local Multicast"
}
if !p.IsIPv4(ip.String()) {
decision = "No IPv4"
}
Log(Debug, "Interface %s: %s. Type: %s. %s", i.Name, addr.String(), ipType, decision)
if decision == "Saving" {
p.LocalIPs = append(p.LocalIPs, ip)
}
}
}
Log(Debug, "%d interfaces were saved", len(p.LocalIPs))
}

// New is an entry point of a P2P library.
func New(argIP, argMac, argDev, argDirect, argHash, argDht, argKeyfile, argKey, argTTL, argLog string, fwd bool, port int, ignoreIPs []string, outboundIP net.IP) *PeerToPeer {
//argDht = "mdht.subut.ai:6881"
Expand Down
50 changes: 50 additions & 0 deletions lib/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,53 @@ func IsInterfaceLocal(ip net.IP) bool {
}
return false
}

// FindNetworkAddresses method lists interfaces available in the system and retrieves their
// IP addresses
func (p *PeerToPeer) FindNetworkAddresses() {
Log(Debug, "Looking for available network interfaces")
inf, err := net.Interfaces()
if err != nil {
Log(Error, "Failed to retrieve list of network interfaces")
return
}
p.LocalIPs = p.LocalIPs[:0]
for _, i := range inf {
addresses, err := i.Addrs()

if err != nil {
Log(Error, "Failed to retrieve address for interface. %v", err)
continue
}
for _, addr := range addresses {
var decision = "Ignoring"
var ipType = "Unknown"
ip, _, err := net.ParseCIDR(addr.String())
if err != nil {
Log(Error, "Failed to parse CIDR notation: %v", err)
}
if ip.IsLoopback() {
ipType = "Loopback"
} else if ip.IsMulticast() {
ipType = "Multicast"
} else if ip.IsGlobalUnicast() {
decision = "Saving"
ipType = "Global Unicast"
} else if ip.IsLinkLocalUnicast() {
ipType = "Link Local Unicast"
} else if ip.IsLinkLocalMulticast() {
ipType = "Link Local Multicast"
} else if ip.IsInterfaceLocalMulticast() {
ipType = "Interface Local Multicast"
}
if !p.IsIPv4(ip.String()) {
decision = "No IPv4"
}
Log(Trace, "Interface %s: %s. Type: %s. %s", i.Name, addr.String(), ipType, decision)
if decision == "Saving" {
p.LocalIPs = append(p.LocalIPs, ip)
}
}
}
Log(Trace, "%d interfaces were saved", len(p.LocalIPs))
}
6 changes: 3 additions & 3 deletions start.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (d *Daemon) run(args *RunArgs, resp *Response) error {
ptp.Log(ptp.Error, "Failed to register instance with bootstrap nodes")
newInst.PTP.Close()
resp.Output = resp.Output + "Failed to register instance"
resp.ExitCode = 2001
resp.ExitCode = 601
return errors.New("Failed to register instance")
}

Expand All @@ -142,7 +142,7 @@ func (d *Daemon) run(args *RunArgs, resp *Response) error {
if err != nil {
newInst.PTP.Close()
resp.Output = resp.Output + err.Error()
resp.ExitCode = 2002
resp.ExitCode = 602
return err
}

Expand All @@ -151,7 +151,7 @@ func (d *Daemon) run(args *RunArgs, resp *Response) error {
ptp.Log(ptp.Error, "Failed to configure network interface: %s", err)
newInst.PTP.Close()
resp.Output = resp.Output + "Failed to configure network: " + err.Error()
resp.ExitCode = 2002
resp.ExitCode = 603
return errors.New("Failed to configure network interface")
}
go newInst.PTP.ListenInterface()
Expand Down

0 comments on commit 2706c1a

Please sign in to comment.