package discovery

import (
	"git.loafle.net/overflow/overflow_probe/discovery/discovery/types"
	"git.loafle.net/overflow/overflow_probe/discovery/discovery/types/timestamp"
	"testing"

	"fmt"
	"github.com/google/gopacket"

	"git.loafle.net/overflow/overflow_probe/discovery/core/scan/zone"
	"git.loafle.net/overflow/overflow_probe/discovery/util/converter"
	"sync"
)

func TestDiscoverTCPPort(t *testing.T) {

	zone := zone.NewZone()

	hh := &types.DiscoveryHost{
		Ip_:            "192.168.1.215",
		Ports_:         make(map[string]*types.DiscoveryPort, 100),
		Ip:             111,
		Mac:            222,
		CreateDate:     timestamp.Now(),
		UpdateDate:     timestamp.Now(),
		Zone:           zone,
		FirstScanRange: 1,
		LastScanRange:  100,
		M:              new(sync.RWMutex),
	}

	wg := sync.WaitGroup{}
	wg.Add(1)
	discoverTcp(&wg, hh, func(port *types.DiscoveryPort) {
		fmt.Println(port.Number)
	})

	wg.Wait()
	//DiscoverPort(hh, false)

}

func TestDiscoverUDPPort(t *testing.T) {

	//zone := types.DiscoveryZone{
	//    Ip:converter.StrToInt("192.168.1.207"),
	//    Netmask:24,
	//    Iface:"",
	//}

	zone := zone.NewZone()

	hh := &types.DiscoveryHost{
		Ip_:            "192.168.1.215",
		Ports_:         make(map[string]*types.DiscoveryPort, 100),
		Ip:             111,
		Mac:            222,
		CreateDate:     timestamp.Now(),
		UpdateDate:     timestamp.Now(),
		Zone:           zone,
		FirstScanRange: 53,
		LastScanRange:  53,
	}

	zone.Hosts_["192.168.1.215"] = hh

	wg := sync.WaitGroup{}
	wg.Add(1)
	discoverUdp(&wg, hh, func(zone *types.DiscoveryZone, ipString, portString string, udpLayer gopacket.Layer) {
		fmt.Println(portString)
	})

	wg.Wait()

	//DiscoverPort(hh, false)

}

func TestIp(t *testing.T) {

	fmt.Println(converter.StrToInt(""))

}
