mirror of
https://github.com/renorris/openfsd
synced 2026-04-21 02:15:31 +08:00
switch geohash technique to 15-bit precision integer
This commit is contained in:
@@ -27,7 +27,7 @@ type FSDClient struct {
|
|||||||
NetworkRating int
|
NetworkRating int
|
||||||
SimulatorType int
|
SimulatorType int
|
||||||
RealName string
|
RealName string
|
||||||
CurrentGeohash string
|
CurrentGeohash uint64
|
||||||
SendFastEnabled bool
|
SendFastEnabled bool
|
||||||
|
|
||||||
Kill chan string // Signal to disconnect this client
|
Kill chan string // Signal to disconnect this client
|
||||||
@@ -367,7 +367,7 @@ func HandleConnection(conn *net.TCPConn) {
|
|||||||
NetworkRating: int(claimedRating),
|
NetworkRating: int(claimedRating),
|
||||||
SimulatorType: addPilotPDU.SimulatorType,
|
SimulatorType: addPilotPDU.SimulatorType,
|
||||||
RealName: addPilotPDU.RealName,
|
RealName: addPilotPDU.RealName,
|
||||||
CurrentGeohash: "",
|
CurrentGeohash: 0,
|
||||||
SendFastEnabled: false,
|
SendFastEnabled: false,
|
||||||
Kill: make(chan string, 1),
|
Kill: make(chan string, 1),
|
||||||
Mailbox: make(chan string, 16),
|
Mailbox: make(chan string, 16),
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -114,7 +114,7 @@ func configurePostOffice() {
|
|||||||
PO = &PostOffice{
|
PO = &PostOffice{
|
||||||
clientRegistry: make(map[string]*FSDClient),
|
clientRegistry: make(map[string]*FSDClient),
|
||||||
supervisorRegistry: make(map[string]*FSDClient),
|
supervisorRegistry: make(map[string]*FSDClient),
|
||||||
geohashRegistry: make(map[string][]*FSDClient),
|
geohashRegistry: make(map[uint64][]*FSDClient),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
type PostOffice struct {
|
type PostOffice struct {
|
||||||
clientRegistry map[string]*FSDClient
|
clientRegistry map[string]*FSDClient
|
||||||
supervisorRegistry map[string]*FSDClient
|
supervisorRegistry map[string]*FSDClient
|
||||||
geohashRegistry map[string][]*FSDClient
|
geohashRegistry map[uint64][]*FSDClient
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ func (p *PostOffice) SendMail(messages []Mail) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case MailTypeBroadcastRanged:
|
case MailTypeBroadcastRanged:
|
||||||
neighbors := geohash.Neighbors(msg.Source.CurrentGeohash)
|
neighbors := geohash.NeighborsInt(msg.Source.CurrentGeohash)
|
||||||
searchHashes := append(neighbors, msg.Source.CurrentGeohash)
|
searchHashes := append(neighbors, msg.Source.CurrentGeohash)
|
||||||
for _, hash := range searchHashes {
|
for _, hash := range searchHashes {
|
||||||
clients, ok := p.geohashRegistry[hash]
|
clients, ok := p.geohashRegistry[hash]
|
||||||
@@ -186,7 +186,7 @@ func (p *PostOffice) SendMail(messages []Mail) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PostOffice) removeClientFromGeohashRegistry(client *FSDClient, hash string) {
|
func (p *PostOffice) removeClientFromGeohashRegistry(client *FSDClient, hash uint64) {
|
||||||
clientList, ok := p.geohashRegistry[client.CurrentGeohash]
|
clientList, ok := p.geohashRegistry[client.CurrentGeohash]
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
@@ -217,7 +217,7 @@ func (p *PostOffice) removeClientFromGeohashRegistry(client *FSDClient, hash str
|
|||||||
// SetLocation updates the internal geohash tracking state for a client, if necessary
|
// SetLocation updates the internal geohash tracking state for a client, if necessary
|
||||||
func (p *PostOffice) SetLocation(client *FSDClient, lat, lng float64) {
|
func (p *PostOffice) SetLocation(client *FSDClient, lat, lng float64) {
|
||||||
// Check if the geohash has changed since we last updated
|
// Check if the geohash has changed since we last updated
|
||||||
hash := geohash.EncodeWithPrecision(lat, lng, 3)
|
hash := geohash.EncodeIntWithPrecision(lat, lng, 15)
|
||||||
if hash == client.CurrentGeohash {
|
if hash == client.CurrentGeohash {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user