mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Merge pull request #211 from loki-project/onion-requests
Make Onion Requests UI Show Countries Rather Than IPs
This commit is contained in:
commit
07df442d3e
296323
assets/csv/geolite2_country_blocks_ipv4.csv
Normal file
296323
assets/csv/geolite2_country_blocks_ipv4.csv
Normal file
File diff suppressed because it is too large
Load Diff
253
assets/csv/geolite2_country_locations_english.csv
Normal file
253
assets/csv/geolite2_country_locations_english.csv
Normal file
@ -0,0 +1,253 @@
|
||||
geoname_id,locale_code,continent_code,continent_name,country_iso_code,country_name,is_in_european_union
|
||||
49518,en,AF,Africa,RW,Rwanda,0
|
||||
51537,en,AF,Africa,SO,Somalia,0
|
||||
69543,en,AS,Asia,YE,Yemen,0
|
||||
99237,en,AS,Asia,IQ,Iraq,0
|
||||
102358,en,AS,Asia,SA,"Saudi Arabia",0
|
||||
130758,en,AS,Asia,IR,Iran,0
|
||||
146669,en,EU,Europe,CY,Cyprus,1
|
||||
149590,en,AF,Africa,TZ,Tanzania,0
|
||||
163843,en,AS,Asia,SY,Syria,0
|
||||
174982,en,AS,Asia,AM,Armenia,0
|
||||
192950,en,AF,Africa,KE,Kenya,0
|
||||
203312,en,AF,Africa,CD,"DR Congo",0
|
||||
223816,en,AF,Africa,DJ,Djibouti,0
|
||||
226074,en,AF,Africa,UG,Uganda,0
|
||||
239880,en,AF,Africa,CF,"Central African Republic",0
|
||||
241170,en,AF,Africa,SC,Seychelles,0
|
||||
248816,en,AS,Asia,JO,"Hashemite Kingdom of Jordan",0
|
||||
272103,en,AS,Asia,LB,Lebanon,0
|
||||
285570,en,AS,Asia,KW,Kuwait,0
|
||||
286963,en,AS,Asia,OM,Oman,0
|
||||
289688,en,AS,Asia,QA,Qatar,0
|
||||
290291,en,AS,Asia,BH,Bahrain,0
|
||||
290557,en,AS,Asia,AE,"United Arab Emirates",0
|
||||
294640,en,AS,Asia,IL,Israel,0
|
||||
298795,en,AS,Asia,TR,Turkey,0
|
||||
337996,en,AF,Africa,ET,Ethiopia,0
|
||||
338010,en,AF,Africa,ER,Eritrea,0
|
||||
357994,en,AF,Africa,EG,Egypt,0
|
||||
366755,en,AF,Africa,SD,Sudan,0
|
||||
390903,en,EU,Europe,GR,Greece,1
|
||||
433561,en,AF,Africa,BI,Burundi,0
|
||||
453733,en,EU,Europe,EE,Estonia,1
|
||||
458258,en,EU,Europe,LV,Latvia,1
|
||||
587116,en,AS,Asia,AZ,Azerbaijan,0
|
||||
597427,en,EU,Europe,LT,"Republic of Lithuania",1
|
||||
607072,en,EU,Europe,SJ,"Svalbard and Jan Mayen",0
|
||||
614540,en,AS,Asia,GE,Georgia,0
|
||||
617790,en,EU,Europe,MD,"Republic of Moldova",0
|
||||
630336,en,EU,Europe,BY,Belarus,0
|
||||
660013,en,EU,Europe,FI,Finland,1
|
||||
661882,en,EU,Europe,AX,"Åland",1
|
||||
690791,en,EU,Europe,UA,Ukraine,0
|
||||
718075,en,EU,Europe,MK,"North Macedonia",0
|
||||
719819,en,EU,Europe,HU,Hungary,1
|
||||
732800,en,EU,Europe,BG,Bulgaria,1
|
||||
783754,en,EU,Europe,AL,Albania,0
|
||||
798544,en,EU,Europe,PL,Poland,1
|
||||
798549,en,EU,Europe,RO,Romania,1
|
||||
831053,en,EU,Europe,XK,Kosovo,0
|
||||
878675,en,AF,Africa,ZW,Zimbabwe,0
|
||||
895949,en,AF,Africa,ZM,Zambia,0
|
||||
921929,en,AF,Africa,KM,Comoros,0
|
||||
927384,en,AF,Africa,MW,Malawi,0
|
||||
932692,en,AF,Africa,LS,Lesotho,0
|
||||
933860,en,AF,Africa,BW,Botswana,0
|
||||
934292,en,AF,Africa,MU,Mauritius,0
|
||||
934841,en,AF,Africa,SZ,Eswatini,0
|
||||
935317,en,AF,Africa,RE,Réunion,1
|
||||
953987,en,AF,Africa,ZA,"South Africa",0
|
||||
1024031,en,AF,Africa,YT,Mayotte,1
|
||||
1036973,en,AF,Africa,MZ,Mozambique,0
|
||||
1062947,en,AF,Africa,MG,Madagascar,0
|
||||
1149361,en,AS,Asia,AF,Afghanistan,0
|
||||
1168579,en,AS,Asia,PK,Pakistan,0
|
||||
1210997,en,AS,Asia,BD,Bangladesh,0
|
||||
1218197,en,AS,Asia,TM,Turkmenistan,0
|
||||
1220409,en,AS,Asia,TJ,Tajikistan,0
|
||||
1227603,en,AS,Asia,LK,"Sri Lanka",0
|
||||
1252634,en,AS,Asia,BT,Bhutan,0
|
||||
1269750,en,AS,Asia,IN,India,0
|
||||
1282028,en,AS,Asia,MV,Maldives,0
|
||||
1282588,en,AS,Asia,IO,"British Indian Ocean Territory",0
|
||||
1282988,en,AS,Asia,NP,Nepal,0
|
||||
1327865,en,AS,Asia,MM,Myanmar,0
|
||||
1512440,en,AS,Asia,UZ,Uzbekistan,0
|
||||
1522867,en,AS,Asia,KZ,Kazakhstan,0
|
||||
1527747,en,AS,Asia,KG,Kyrgyzstan,0
|
||||
1546748,en,AN,Antarctica,TF,"French Southern Territories",0
|
||||
1547314,en,AN,Antarctica,HM,"Heard Island and McDonald Islands",0
|
||||
1547376,en,AS,Asia,CC,"Cocos [Keeling] Islands",0
|
||||
1559582,en,OC,Oceania,PW,Palau,0
|
||||
1562822,en,AS,Asia,VN,Vietnam,0
|
||||
1605651,en,AS,Asia,TH,Thailand,0
|
||||
1643084,en,AS,Asia,ID,Indonesia,0
|
||||
1655842,en,AS,Asia,LA,Laos,0
|
||||
1668284,en,AS,Asia,TW,Taiwan,0
|
||||
1694008,en,AS,Asia,PH,Philippines,0
|
||||
1733045,en,AS,Asia,MY,Malaysia,0
|
||||
1814991,en,AS,Asia,CN,China,0
|
||||
1819730,en,AS,Asia,HK,"Hong Kong",0
|
||||
1820814,en,AS,Asia,BN,Brunei,0
|
||||
1821275,en,AS,Asia,MO,Macao,0
|
||||
1831722,en,AS,Asia,KH,Cambodia,0
|
||||
1835841,en,AS,Asia,KR,"South Korea",0
|
||||
1861060,en,AS,Asia,JP,Japan,0
|
||||
1873107,en,AS,Asia,KP,"North Korea",0
|
||||
1880251,en,AS,Asia,SG,Singapore,0
|
||||
1899402,en,OC,Oceania,CK,"Cook Islands",0
|
||||
1966436,en,OC,Oceania,TL,"East Timor",0
|
||||
2017370,en,EU,Europe,RU,Russia,0
|
||||
2029969,en,AS,Asia,MN,Mongolia,0
|
||||
2077456,en,OC,Oceania,AU,Australia,0
|
||||
2078138,en,OC,Oceania,CX,"Christmas Island",0
|
||||
2080185,en,OC,Oceania,MH,"Marshall Islands",0
|
||||
2081918,en,OC,Oceania,FM,"Federated States of Micronesia",0
|
||||
2088628,en,OC,Oceania,PG,"Papua New Guinea",0
|
||||
2103350,en,OC,Oceania,SB,"Solomon Islands",0
|
||||
2110297,en,OC,Oceania,TV,Tuvalu,0
|
||||
2110425,en,OC,Oceania,NR,Nauru,0
|
||||
2134431,en,OC,Oceania,VU,Vanuatu,0
|
||||
2139685,en,OC,Oceania,NC,"New Caledonia",0
|
||||
2155115,en,OC,Oceania,NF,"Norfolk Island",0
|
||||
2186224,en,OC,Oceania,NZ,"New Zealand",0
|
||||
2205218,en,OC,Oceania,FJ,Fiji,0
|
||||
2215636,en,AF,Africa,LY,Libya,0
|
||||
2233387,en,AF,Africa,CM,Cameroon,0
|
||||
2245662,en,AF,Africa,SN,Senegal,0
|
||||
2260494,en,AF,Africa,CG,"Congo Republic",0
|
||||
2264397,en,EU,Europe,PT,Portugal,1
|
||||
2275384,en,AF,Africa,LR,Liberia,0
|
||||
2287781,en,AF,Africa,CI,"Ivory Coast",0
|
||||
2300660,en,AF,Africa,GH,Ghana,0
|
||||
2309096,en,AF,Africa,GQ,"Equatorial Guinea",0
|
||||
2328926,en,AF,Africa,NG,Nigeria,0
|
||||
2361809,en,AF,Africa,BF,"Burkina Faso",0
|
||||
2363686,en,AF,Africa,TG,Togo,0
|
||||
2372248,en,AF,Africa,GW,Guinea-Bissau,0
|
||||
2378080,en,AF,Africa,MR,Mauritania,0
|
||||
2395170,en,AF,Africa,BJ,Benin,0
|
||||
2400553,en,AF,Africa,GA,Gabon,0
|
||||
2403846,en,AF,Africa,SL,"Sierra Leone",0
|
||||
2410758,en,AF,Africa,ST,"São Tomé and Príncipe",0
|
||||
2411586,en,EU,Europe,GI,Gibraltar,1
|
||||
2413451,en,AF,Africa,GM,Gambia,0
|
||||
2420477,en,AF,Africa,GN,Guinea,0
|
||||
2434508,en,AF,Africa,TD,Chad,0
|
||||
2440476,en,AF,Africa,NE,Niger,0
|
||||
2453866,en,AF,Africa,ML,Mali,0
|
||||
2461445,en,AF,Africa,EH,"Western Sahara",0
|
||||
2464461,en,AF,Africa,TN,Tunisia,0
|
||||
2510769,en,EU,Europe,ES,Spain,1
|
||||
2542007,en,AF,Africa,MA,Morocco,0
|
||||
2562770,en,EU,Europe,MT,Malta,1
|
||||
2589581,en,AF,Africa,DZ,Algeria,0
|
||||
2622320,en,EU,Europe,FO,"Faroe Islands",0
|
||||
2623032,en,EU,Europe,DK,Denmark,1
|
||||
2629691,en,EU,Europe,IS,Iceland,0
|
||||
2635167,en,EU,Europe,GB,"United Kingdom",1
|
||||
2658434,en,EU,Europe,CH,Switzerland,0
|
||||
2661886,en,EU,Europe,SE,Sweden,1
|
||||
2750405,en,EU,Europe,NL,Netherlands,1
|
||||
2782113,en,EU,Europe,AT,Austria,1
|
||||
2802361,en,EU,Europe,BE,Belgium,1
|
||||
2921044,en,EU,Europe,DE,Germany,1
|
||||
2960313,en,EU,Europe,LU,Luxembourg,1
|
||||
2963597,en,EU,Europe,IE,Ireland,1
|
||||
2993457,en,EU,Europe,MC,Monaco,0
|
||||
3017382,en,EU,Europe,FR,France,1
|
||||
3041565,en,EU,Europe,AD,Andorra,0
|
||||
3042058,en,EU,Europe,LI,Liechtenstein,0
|
||||
3042142,en,EU,Europe,JE,Jersey,0
|
||||
3042225,en,EU,Europe,IM,"Isle of Man",0
|
||||
3042362,en,EU,Europe,GG,Guernsey,0
|
||||
3057568,en,EU,Europe,SK,Slovakia,1
|
||||
3077311,en,EU,Europe,CZ,Czechia,1
|
||||
3144096,en,EU,Europe,NO,Norway,0
|
||||
3164670,en,EU,Europe,VA,"Vatican City",0
|
||||
3168068,en,EU,Europe,SM,"San Marino",0
|
||||
3175395,en,EU,Europe,IT,Italy,1
|
||||
3190538,en,EU,Europe,SI,Slovenia,1
|
||||
3194884,en,EU,Europe,ME,Montenegro,0
|
||||
3202326,en,EU,Europe,HR,Croatia,1
|
||||
3277605,en,EU,Europe,BA,"Bosnia and Herzegovina",0
|
||||
3351879,en,AF,Africa,AO,Angola,0
|
||||
3355338,en,AF,Africa,NA,Namibia,0
|
||||
3370751,en,AF,Africa,SH,"Saint Helena",0
|
||||
3371123,en,AN,Antarctica,BV,"Bouvet Island",0
|
||||
3374084,en,NA,"North America",BB,Barbados,0
|
||||
3374766,en,AF,Africa,CV,"Cabo Verde",0
|
||||
3378535,en,SA,"South America",GY,Guyana,0
|
||||
3381670,en,SA,"South America",GF,"French Guiana",1
|
||||
3382998,en,SA,"South America",SR,Suriname,0
|
||||
3424932,en,NA,"North America",PM,"Saint Pierre and Miquelon",0
|
||||
3425505,en,NA,"North America",GL,Greenland,0
|
||||
3437598,en,SA,"South America",PY,Paraguay,0
|
||||
3439705,en,SA,"South America",UY,Uruguay,0
|
||||
3469034,en,SA,"South America",BR,Brazil,0
|
||||
3474414,en,SA,"South America",FK,"Falkland Islands",0
|
||||
3474415,en,AN,Antarctica,GS,"South Georgia and the South Sandwich Islands",0
|
||||
3489940,en,NA,"North America",JM,Jamaica,0
|
||||
3508796,en,NA,"North America",DO,"Dominican Republic",0
|
||||
3562981,en,NA,"North America",CU,Cuba,0
|
||||
3570311,en,NA,"North America",MQ,Martinique,1
|
||||
3572887,en,NA,"North America",BS,Bahamas,0
|
||||
3573345,en,NA,"North America",BM,Bermuda,0
|
||||
3573511,en,NA,"North America",AI,Anguilla,0
|
||||
3573591,en,NA,"North America",TT,"Trinidad and Tobago",0
|
||||
3575174,en,NA,"North America",KN,"St Kitts and Nevis",0
|
||||
3575830,en,NA,"North America",DM,Dominica,0
|
||||
3576396,en,NA,"North America",AG,"Antigua and Barbuda",0
|
||||
3576468,en,NA,"North America",LC,"Saint Lucia",0
|
||||
3576916,en,NA,"North America",TC,"Turks and Caicos Islands",0
|
||||
3577279,en,NA,"North America",AW,Aruba,0
|
||||
3577718,en,NA,"North America",VG,"British Virgin Islands",0
|
||||
3577815,en,NA,"North America",VC,"Saint Vincent and the Grenadines",0
|
||||
3578097,en,NA,"North America",MS,Montserrat,0
|
||||
3578421,en,NA,"North America",MF,"Saint Martin",1
|
||||
3578476,en,NA,"North America",BL,"Saint Barthélemy",0
|
||||
3579143,en,NA,"North America",GP,Guadeloupe,1
|
||||
3580239,en,NA,"North America",GD,Grenada,0
|
||||
3580718,en,NA,"North America",KY,"Cayman Islands",0
|
||||
3582678,en,NA,"North America",BZ,Belize,0
|
||||
3585968,en,NA,"North America",SV,"El Salvador",0
|
||||
3595528,en,NA,"North America",GT,Guatemala,0
|
||||
3608932,en,NA,"North America",HN,Honduras,0
|
||||
3617476,en,NA,"North America",NI,Nicaragua,0
|
||||
3624060,en,NA,"North America",CR,"Costa Rica",0
|
||||
3625428,en,SA,"South America",VE,Venezuela,0
|
||||
3658394,en,SA,"South America",EC,Ecuador,0
|
||||
3686110,en,SA,"South America",CO,Colombia,0
|
||||
3703430,en,NA,"North America",PA,Panama,0
|
||||
3723988,en,NA,"North America",HT,Haiti,0
|
||||
3865483,en,SA,"South America",AR,Argentina,0
|
||||
3895114,en,SA,"South America",CL,Chile,0
|
||||
3923057,en,SA,"South America",BO,Bolivia,0
|
||||
3932488,en,SA,"South America",PE,Peru,0
|
||||
3996063,en,NA,"North America",MX,Mexico,0
|
||||
4030656,en,OC,Oceania,PF,"French Polynesia",0
|
||||
4030699,en,OC,Oceania,PN,"Pitcairn Islands",0
|
||||
4030945,en,OC,Oceania,KI,Kiribati,0
|
||||
4031074,en,OC,Oceania,TK,Tokelau,0
|
||||
4032283,en,OC,Oceania,TO,Tonga,0
|
||||
4034749,en,OC,Oceania,WF,"Wallis and Futuna",0
|
||||
4034894,en,OC,Oceania,WS,Samoa,0
|
||||
4036232,en,OC,Oceania,NU,Niue,0
|
||||
4041468,en,OC,Oceania,MP,"Northern Mariana Islands",0
|
||||
4043988,en,OC,Oceania,GU,Guam,0
|
||||
4566966,en,NA,"North America",PR,"Puerto Rico",0
|
||||
4796775,en,NA,"North America",VI,"U.S. Virgin Islands",0
|
||||
5854968,en,OC,Oceania,UM,"U.S. Minor Outlying Islands",0
|
||||
5880801,en,OC,Oceania,AS,"American Samoa",0
|
||||
6251999,en,NA,"North America",CA,Canada,0
|
||||
6252001,en,NA,"North America",US,"United States",0
|
||||
6254930,en,AS,Asia,PS,Palestine,0
|
||||
6255147,en,AS,Asia,,,0
|
||||
6255148,en,EU,Europe,,,0
|
||||
6290252,en,EU,Europe,RS,Serbia,0
|
||||
6697173,en,AN,Antarctica,AQ,Antarctica,0
|
||||
7609695,en,NA,"North America",SX,"Sint Maarten",0
|
||||
7626836,en,NA,"North America",CW,Curaçao,0
|
||||
7626844,en,NA,"North America",BQ,"Bonaire, Sint Eustatius, and Saba",0
|
||||
7909807,en,AF,Africa,SS,"South Sudan",0
|
|
@ -8,6 +8,7 @@ buildscript {
|
||||
ext.rss_parser_version = "2.0.4"
|
||||
ext.google_services_version = "4.3.3"
|
||||
ext.firebase_messaging_version = "18.0.0"
|
||||
ext.opencsv_version = "4.6"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
@ -188,6 +189,7 @@ dependencies {
|
||||
implementation "com.jakewharton.rxbinding3:rxbinding:3.1.0"
|
||||
implementation "com.github.tbruyelle:rxpermissions:0.10.2"
|
||||
implementation "com.github.ybq:Android-SpinKit:1.4.0"
|
||||
implementation "com.opencsv:opencsv:$opencsv_version"
|
||||
}
|
||||
|
||||
def canonicalVersionCode = 52
|
||||
|
@ -45,10 +45,10 @@
|
||||
|
||||
<Button
|
||||
style="@style/MediumProminentOutlineButton"
|
||||
android:id="@+id/rebuildPathButton"
|
||||
android:id="@+id/learnMoreButton"
|
||||
android:layout_width="196dp"
|
||||
android:layout_height="@dimen/medium_button_height"
|
||||
android:layout_marginBottom="@dimen/medium_spacing"
|
||||
android:text="@string/activity_path_rebuild_path_button_title" />
|
||||
android:text="@string/activity_path_learn_more_button_title" />
|
||||
|
||||
</LinearLayout>
|
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/learnMoreButton"
|
||||
android:icon="@drawable/ic_question_mark"
|
||||
app:showAsAction="always" />
|
||||
|
||||
</menu>
|
@ -1742,12 +1742,12 @@
|
||||
<string name="view_seed_reminder_subtitle_3">Make sure to store your recovery phrase in a safe place</string>
|
||||
|
||||
<string name="activity_path_title">Path</string>
|
||||
<string name="activity_path_explanation">Session hides your IP by bouncing your messages through several Service Nodes in Session\'s decentralized network. These are the Service Nodes currently being used by your device:</string>
|
||||
<string name="activity_path_explanation">Session hides your IP by bouncing your messages through several Service Nodes in Session\'s decentralized network. These are the countries your connection is currently being bounced through:</string>
|
||||
<string name="activity_path_device_row_title">You</string>
|
||||
<string name="activity_path_guard_node_row_title">Guard Node</string>
|
||||
<string name="activity_path_service_node_row_title">Service Node</string>
|
||||
<string name="activity_path_destination_row_title">Destination</string>
|
||||
<string name="activity_path_rebuild_path_button_title">Rebuild Path</string>
|
||||
<string name="activity_path_learn_more_button_title">Learn More</string>
|
||||
|
||||
<string name="activity_create_private_chat_title">New Session</string>
|
||||
<string name="activity_create_private_chat_enter_session_id_tab_title">Enter Session ID</string>
|
||||
|
@ -34,10 +34,7 @@ import org.thoughtcrime.securesms.database.model.ThreadRecord
|
||||
import org.thoughtcrime.securesms.loki.dialogs.PNModeBottomSheet
|
||||
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol
|
||||
import org.thoughtcrime.securesms.loki.protocol.LokiSessionResetImplementation
|
||||
import org.thoughtcrime.securesms.loki.utilities.getColorWithID
|
||||
import org.thoughtcrime.securesms.loki.utilities.push
|
||||
import org.thoughtcrime.securesms.loki.utilities.recipient
|
||||
import org.thoughtcrime.securesms.loki.utilities.show
|
||||
import org.thoughtcrime.securesms.loki.utilities.*
|
||||
import org.thoughtcrime.securesms.loki.views.ConversationView
|
||||
import org.thoughtcrime.securesms.loki.views.NewConversationButtonSetViewDelegate
|
||||
import org.thoughtcrime.securesms.loki.views.SeedReminderViewDelegate
|
||||
@ -70,6 +67,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
||||
super.onCreate(savedInstanceState, isReady)
|
||||
IP2Country.configureIfNeeded(this)
|
||||
// Process any outstanding deletes
|
||||
val threadDatabase = DatabaseFactory.getThreadDatabase(this)
|
||||
val archivedConversationCount = threadDatabase.archivedConversationListCount
|
||||
|
@ -11,8 +11,6 @@ import android.support.v4.content.LocalBroadcastManager
|
||||
import android.util.AttributeSet
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
@ -21,13 +19,9 @@ import android.widget.Toast
|
||||
import kotlinx.android.synthetic.main.activity_path.*
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.loki.utilities.animateSizeChange
|
||||
import org.thoughtcrime.securesms.loki.utilities.fadeIn
|
||||
import org.thoughtcrime.securesms.loki.utilities.fadeOut
|
||||
import org.thoughtcrime.securesms.loki.utilities.getColorWithID
|
||||
import org.whispersystems.signalservice.loki.api.onionrequests.OnionRequestAPI
|
||||
import org.thoughtcrime.securesms.loki.utilities.*
|
||||
import org.whispersystems.signalservice.loki.api.Snode
|
||||
import org.whispersystems.signalservice.loki.api.onionrequests.OnionRequestAPI
|
||||
|
||||
class PathActivity : PassphraseRequiredActionBarActivity() {
|
||||
private val broadcastReceivers = mutableListOf<BroadcastReceiver>()
|
||||
@ -37,7 +31,7 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
|
||||
super.onCreate(savedInstanceState, isReady)
|
||||
setContentView(R.layout.activity_path)
|
||||
supportActionBar!!.title = resources.getString(R.string.activity_path_title)
|
||||
rebuildPathButton.setOnClickListener { rebuildPath() }
|
||||
learnMoreButton.setOnClickListener { learnMore() }
|
||||
update(false)
|
||||
registerObservers()
|
||||
}
|
||||
@ -61,11 +55,6 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(pathsBuiltReceiver, IntentFilter("pathsBuilt"))
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_path, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
for (receiver in broadcastReceivers) {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver)
|
||||
@ -142,21 +131,12 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
|
||||
|
||||
private fun getPathRow(snode: Snode, location: LineView.Location, dotAnimationStartDelay: Long, dotAnimationRepeatInterval: Long, isGuardSnode: Boolean): LinearLayout {
|
||||
val title = if (isGuardSnode) resources.getString(R.string.activity_path_guard_node_row_title) else resources.getString(R.string.activity_path_service_node_row_title)
|
||||
val subtitle = snode.toString().removePrefix("https://").substringBefore(":")
|
||||
val subtitle = IP2Country.shared.getCountry(snode.ip)
|
||||
return getPathRow(title, subtitle, location, dotAnimationStartDelay, dotAnimationRepeatInterval)
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Interaction
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
val id = item.itemId
|
||||
when(id) {
|
||||
R.id.learnMoreButton -> learnMore()
|
||||
else -> { /* Do nothing */ }
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun learnMore() {
|
||||
try {
|
||||
val url = "https://getsession.org/faq/#onion-routing"
|
||||
@ -166,13 +146,6 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
|
||||
Toast.makeText(this, R.string.invalid_url, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun rebuildPath() {
|
||||
DatabaseFactory.getLokiAPIDatabase(this).clearOnionRequestPaths()
|
||||
OnionRequestAPI.guardSnodes = setOf()
|
||||
OnionRequestAPI.paths = listOf()
|
||||
OnionRequestAPI.buildPaths()
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Line View
|
||||
|
116
src/org/thoughtcrime/securesms/loki/utilities/IP2Country.kt
Normal file
116
src/org/thoughtcrime/securesms/loki/utilities/IP2Country.kt
Normal file
@ -0,0 +1,116 @@
|
||||
package org.thoughtcrime.securesms.loki.utilities
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.support.v4.content.LocalBroadcastManager
|
||||
import android.util.Log
|
||||
import com.opencsv.CSVReader
|
||||
import org.whispersystems.signalservice.loki.api.onionrequests.OnionRequestAPI
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.FileReader
|
||||
|
||||
class IP2Country private constructor(private val context: Context) {
|
||||
private val pathsBuiltEventReceiver: BroadcastReceiver
|
||||
private val countryNamesCache = mutableMapOf<String, String>()
|
||||
|
||||
private val ipv4Table by lazy {
|
||||
loadFile("geolite2_country_blocks_ipv4.csv")
|
||||
}
|
||||
|
||||
private val countryNamesTable by lazy {
|
||||
loadFile("geolite2_country_locations_english.csv")
|
||||
}
|
||||
|
||||
// region Initialization
|
||||
companion object {
|
||||
|
||||
public lateinit var shared: IP2Country
|
||||
|
||||
public fun configureIfNeeded(context: Context) {
|
||||
if (::shared.isInitialized) { return; }
|
||||
shared = IP2Country(context)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
preloadCountriesIfNeeded()
|
||||
pathsBuiltEventReceiver = object : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
preloadCountriesIfNeeded()
|
||||
}
|
||||
}
|
||||
LocalBroadcastManager.getInstance(context).registerReceiver(pathsBuiltEventReceiver, IntentFilter("pathsBuilt"))
|
||||
}
|
||||
|
||||
// TODO: Deinit?
|
||||
// endregion
|
||||
|
||||
// region Implementation
|
||||
private fun loadFile(fileName: String): File {
|
||||
val directory = File(context.applicationInfo.dataDir)
|
||||
val file = File(directory, fileName)
|
||||
if (directory.list().contains(fileName)) { return file }
|
||||
val inputStream = context.assets.open("csv/$fileName")
|
||||
val outputStream = FileOutputStream(file)
|
||||
val buffer = ByteArray(1024)
|
||||
while (true) {
|
||||
val count = inputStream.read(buffer)
|
||||
if (count < 0) { break }
|
||||
outputStream.write(buffer, 0, count)
|
||||
}
|
||||
inputStream.close()
|
||||
outputStream.close()
|
||||
return file
|
||||
}
|
||||
|
||||
fun getCountry(ip: String): String {
|
||||
var truncatedIP = ip
|
||||
fun getCountryInternal(): String {
|
||||
val country = countryNamesCache[ip]
|
||||
if (country != null) { return country }
|
||||
val ipv4TableReader = CSVReader(FileReader(ipv4Table.absoluteFile))
|
||||
val countryNamesTableReader = CSVReader(FileReader(countryNamesTable.absoluteFile))
|
||||
var ipv4TableLine = ipv4TableReader.readNext()
|
||||
while (ipv4TableLine != null) {
|
||||
if (!ipv4TableLine[0].startsWith(truncatedIP)) {
|
||||
ipv4TableLine = ipv4TableReader.readNext()
|
||||
continue
|
||||
}
|
||||
val countryID = ipv4TableLine[1]
|
||||
var countryNamesTableLine = countryNamesTableReader.readNext()
|
||||
while (countryNamesTableLine != null) {
|
||||
if (countryNamesTableLine[0] != countryID) {
|
||||
countryNamesTableLine = countryNamesTableReader.readNext()
|
||||
continue
|
||||
}
|
||||
@Suppress("NAME_SHADOWING") val country = countryNamesTableLine[5]
|
||||
countryNamesCache[ip] = country
|
||||
return country
|
||||
}
|
||||
}
|
||||
if (truncatedIP.contains(".") && !truncatedIP.endsWith(".")) { // The fuzziest we want to go is xxx.x
|
||||
truncatedIP = truncatedIP.dropLast(1)
|
||||
if (truncatedIP.endsWith(".")) { truncatedIP = truncatedIP.dropLast(1) }
|
||||
return getCountryInternal()
|
||||
} else {
|
||||
return "Unknown Country"
|
||||
}
|
||||
}
|
||||
return getCountryInternal()
|
||||
}
|
||||
|
||||
private fun preloadCountriesIfNeeded() {
|
||||
Thread {
|
||||
val path = OnionRequestAPI.paths.firstOrNull() ?: return@Thread
|
||||
path.forEach { snode ->
|
||||
getCountry(snode.ip) // Preload if needed
|
||||
}
|
||||
Log.d("Loki", "Finished preloading onion request path countries.")
|
||||
}.start()
|
||||
}
|
||||
// endregion
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user