@ -58,7 +58,8 @@ public extension LokiAPI {
" limit " : 24 ,
" fields " : [
" public_ip " : true ,
" storage_port " : true
" storage_port " : true ,
" pubkey_ed25519 " : true
]
]
] )
@ -67,11 +68,11 @@ public extension LokiAPI {
let rawResponse = intermediate . responseObject
guard let json = rawResponse as ? JSON , let intermediate = json [ " result " ] as ? JSON , let rawTargets = intermediate [ " service_node_states " ] as ? [ JSON ] else { throw " Failed to update random snode pool from: \( rawResponse ) . " }
randomSnodePool = try Set ( rawTargets . flatMap { rawTarget in
guard let address = rawTarget [ " public_ip " ] as ? String , let port = rawTarget [ " storage_port " ] as ? Int , address != " 0.0.0.0 " else {
guard let address = rawTarget [ " public_ip " ] as ? String , let port = rawTarget [ " storage_port " ] as ? Int , let publicKey = rawTarget [ " pubkey_ed25519 " ] as ? String , address != " 0.0.0.0 " else {
print ( " Failed to update random snode pool from: \( rawTarget ) . " )
return nil
}
return LokiAPITarget ( address : " https:// \( address ) " , port : UInt16 ( port ) )
return LokiAPITarget ( address : " https:// \( address ) " , port : UInt16 ( port ) , publicKey : publicKey )
} )
return randomSnodePool . randomElement ( ) !
} . recover ( on : DispatchQueue . global ( ) ) { error -> Promise < LokiAPITarget > in
@ -108,11 +109,11 @@ public extension LokiAPI {
return [ ]
}
return rawSnodes . flatMap { rawSnode in
guard let address = rawSnode [ " ip " ] as ? String , let portAsString = rawSnode [ " port " ] as ? String , let port = UInt16 ( portAsString ) , address != " 0.0.0.0 " else {
guard let address = rawSnode [ " ip " ] as ? String , let portAsString = rawSnode [ " port " ] as ? String , let port = UInt16 ( portAsString ) , let publicKey = rawSnode [ " pubkey_ed25519 " ] as ? String , address != " 0.0.0.0 " else {
print ( " [Loki] Failed to parse target from: \( rawSnode ) . " )
return nil
}
return LokiAPITarget ( address : " https:// \( address ) " , port : port )
return LokiAPITarget ( address : " https:// \( address ) " , port : port , publicKey : publicKey )
}
}
}