From 59b02eade556f0b6d569043135be8dd09c529fa6 Mon Sep 17 00:00:00 2001 From: Reese Norris Date: Tue, 9 Apr 2024 15:18:18 -0700 Subject: [PATCH] switch geohash technique to 15-bit precision integer --- fsd_client.go | 4 ++-- main.go | 2 +- post_office.go | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fsd_client.go b/fsd_client.go index ced5b6a..367b06a 100644 --- a/fsd_client.go +++ b/fsd_client.go @@ -27,7 +27,7 @@ type FSDClient struct { NetworkRating int SimulatorType int RealName string - CurrentGeohash string + CurrentGeohash uint64 SendFastEnabled bool Kill chan string // Signal to disconnect this client @@ -367,7 +367,7 @@ func HandleConnection(conn *net.TCPConn) { NetworkRating: int(claimedRating), SimulatorType: addPilotPDU.SimulatorType, RealName: addPilotPDU.RealName, - CurrentGeohash: "", + CurrentGeohash: 0, SendFastEnabled: false, Kill: make(chan string, 1), Mailbox: make(chan string, 16), diff --git a/main.go b/main.go index 1a2d4db..4acd5a7 100644 --- a/main.go +++ b/main.go @@ -114,7 +114,7 @@ func configurePostOffice() { PO = &PostOffice{ clientRegistry: make(map[string]*FSDClient), supervisorRegistry: make(map[string]*FSDClient), - geohashRegistry: make(map[string][]*FSDClient), + geohashRegistry: make(map[uint64][]*FSDClient), } } diff --git a/post_office.go b/post_office.go index a75d3b9..f28abd5 100644 --- a/post_office.go +++ b/post_office.go @@ -11,7 +11,7 @@ import ( type PostOffice struct { clientRegistry map[string]*FSDClient supervisorRegistry map[string]*FSDClient - geohashRegistry map[string][]*FSDClient + geohashRegistry map[uint64][]*FSDClient lock sync.RWMutex } @@ -141,7 +141,7 @@ func (p *PostOffice) SendMail(messages []Mail) { } } case MailTypeBroadcastRanged: - neighbors := geohash.Neighbors(msg.Source.CurrentGeohash) + neighbors := geohash.NeighborsInt(msg.Source.CurrentGeohash) searchHashes := append(neighbors, msg.Source.CurrentGeohash) for _, hash := range searchHashes { 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] if !ok { 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 func (p *PostOffice) SetLocation(client *FSDClient, lat, lng float64) { // 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 { return }