Elect one fleet torrent seeder per AWS VPC via IMDS cloud_instance_meta.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Agents read vpc-id from EC2 IMDS on auth; the server scopes subnet_primary_seeder to vpc-id with /24 fallback, exposes VPC seeder badges, and documents cross-VPC gossip via peering/TGW.
This commit is contained in:
92
server/internal/api/cloud_instance_meta.go
Normal file
92
server/internal/api/cloud_instance_meta.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"crypto-miner-server/internal/models"
|
||||
)
|
||||
|
||||
type CloudInstanceMeta struct {
|
||||
VpcID string `json:"vpc_id,omitempty"`
|
||||
SubnetID string `json:"subnet_id,omitempty"`
|
||||
Region string `json:"region,omitempty"`
|
||||
}
|
||||
|
||||
func (m CloudInstanceMeta) present() bool {
|
||||
return strings.TrimSpace(m.VpcID) != "" || strings.TrimSpace(m.SubnetID) != "" || strings.TrimSpace(m.Region) != ""
|
||||
}
|
||||
|
||||
func normalizeCloudInstanceMeta(m CloudInstanceMeta) CloudInstanceMeta {
|
||||
return CloudInstanceMeta{
|
||||
VpcID: strings.TrimSpace(m.VpcID), SubnetID: strings.TrimSpace(m.SubnetID), Region: strings.TrimSpace(m.Region),
|
||||
}
|
||||
}
|
||||
|
||||
func (h *WSHub) storeAgentCloudMeta(agentID string, meta CloudInstanceMeta) {
|
||||
meta = normalizeCloudInstanceMeta(meta)
|
||||
if !meta.present() {
|
||||
return
|
||||
}
|
||||
h.mu.Lock()
|
||||
tel, ok := h.agentLiveTelemetry[agentID]
|
||||
if !ok {
|
||||
tel = map[string]interface{}{}
|
||||
h.agentLiveTelemetry[agentID] = tel
|
||||
}
|
||||
tel["cloud_instance_meta"] = map[string]interface{}{
|
||||
"vpc_id": meta.VpcID, "subnet_id": meta.SubnetID, "region": meta.Region,
|
||||
}
|
||||
h.mu.Unlock()
|
||||
}
|
||||
|
||||
func (h *WSHub) agentCloudMetaLocked(agentID string) CloudInstanceMeta {
|
||||
if tel, ok := h.agentLiveTelemetry[agentID]; ok {
|
||||
if raw, ok := tel["cloud_instance_meta"].(map[string]interface{}); ok {
|
||||
meta := CloudInstanceMeta{}
|
||||
if v, ok := raw["vpc_id"].(string); ok {
|
||||
meta.VpcID = v
|
||||
}
|
||||
if v, ok := raw["subnet_id"].(string); ok {
|
||||
meta.SubnetID = v
|
||||
}
|
||||
if v, ok := raw["region"].(string); ok {
|
||||
meta.Region = v
|
||||
}
|
||||
return normalizeCloudInstanceMeta(meta)
|
||||
}
|
||||
}
|
||||
return CloudInstanceMeta{}
|
||||
}
|
||||
|
||||
func primarySeederScope(clientIP string, meta CloudInstanceMeta) string {
|
||||
if strings.TrimSpace(meta.VpcID) != "" {
|
||||
return strings.TrimSpace(meta.VpcID)
|
||||
}
|
||||
return subnetPrefix24(clientIP)
|
||||
}
|
||||
|
||||
func (h *WSHub) agentMatchesPrimaryScopeLocked(agentID, scope string) bool {
|
||||
meta := h.agentCloudMetaLocked(agentID)
|
||||
if meta.VpcID != "" {
|
||||
return meta.VpcID == scope
|
||||
}
|
||||
return subnetPrefix24(h.agentIPLocked(agentID)) == scope
|
||||
}
|
||||
|
||||
func (h *WSHub) attachVPCSeederTelemetry(agent *models.Agent, agentID, _, role, primaryPick string) {
|
||||
if agent == nil {
|
||||
return
|
||||
}
|
||||
meta := h.agentCloudMetaLocked(agentID)
|
||||
if !meta.present() {
|
||||
return
|
||||
}
|
||||
agent.CloudVpcID = meta.VpcID
|
||||
agent.CloudSubnetID = meta.SubnetID
|
||||
agent.CloudRegion = meta.Region
|
||||
if role != "seeder" || primaryPick == "" {
|
||||
return
|
||||
}
|
||||
primary := primaryPick == agentID
|
||||
agent.VPCPrimarySeeder = &primary
|
||||
}
|
||||
Reference in New Issue
Block a user