测试
This commit is contained in:
parent
676acb3198
commit
4d0f25400a
|
@ -23,7 +23,7 @@ type Config struct {
|
|||
} `yaml:"network"`
|
||||
|
||||
IPv4Nodes map[uint32]string
|
||||
Lock sync.Mutex
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
var config = NewConfig()
|
||||
|
@ -56,3 +56,9 @@ func NewConfig() *Config {
|
|||
|
||||
return cnf
|
||||
}
|
||||
|
||||
func (cnf *Config) Lock(do func()) {
|
||||
cnf.lock.Lock()
|
||||
defer cnf.lock.Unlock()
|
||||
do()
|
||||
}
|
||||
|
|
11
tap.go
11
tap.go
|
@ -167,12 +167,15 @@ func (nc *NetCard) runRead() {
|
|||
continue
|
||||
}
|
||||
|
||||
var realAddr string
|
||||
config.Lock.Lock()
|
||||
if _, ok = config.IPv4Nodes[binary.LittleEndian.Uint32([]byte(waterutil.IPv4Destination(rframe)))]; !ok {
|
||||
var realAddr string = ""
|
||||
config.Lock(func() {
|
||||
if realAddr, ok = config.IPv4Nodes[binary.LittleEndian.Uint32([]byte(waterutil.IPv4Destination(rframe)))]; !ok {
|
||||
return
|
||||
}
|
||||
})
|
||||
if realAddr == "" {
|
||||
continue
|
||||
}
|
||||
config.Lock.Unlock()
|
||||
|
||||
// log.Printf("Payload: % x\n", rframe.Payload())
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user