add: 新增路由报告模块接口

This commit is contained in:
sjlleo
2022-05-14 16:55:28 +08:00
parent 6792bafb02
commit 06ee8f7373
2 changed files with 51 additions and 0 deletions

27
util/reporter/reporter.go Normal file
View File

@@ -0,0 +1,27 @@
package reporter
import (
"fmt"
"github.com/xgadget-lab/nexttrace/methods"
)
type Reporter interface {
Print()
}
func New(rs map[uint16][]methods.TracerouteHop) Reporter {
r := reporter{
routeResult: rs,
}
fmt.Println(r)
return &r
}
type reporter struct {
routeResult map[uint16][]methods.TracerouteHop
}
func (r *reporter) Print() {
fmt.Println(r)
}

View File

@@ -0,0 +1,24 @@
package reporter
import (
"testing"
"time"
"github.com/xgadget-lab/nexttrace/methods"
"github.com/xgadget-lab/nexttrace/methods/tcp"
"github.com/xgadget-lab/nexttrace/util"
)
func TestPrint(t *testing.T) {
ip := util.DomainLookUp("1.1.1.1")
tcpTraceroute := tcp.New(ip, methods.TracerouteConfig{
MaxHops: uint16(30),
NumMeasurements: uint16(1),
ParallelRequests: uint16(1),
Port: 80,
Timeout: time.Second / 2,
})
res, _ := tcpTraceroute.Start()
r := New(*res)
r.Print()
}