Moving hosts.txt to sqlite #51

Open
opened 2025-04-21 14:45:25 -04:00 by idk · 8 comments
Owner

Opened 9 years ago

Last modified 7 years ago

#692assignedenhancement

Moving hosts.txt to sqlite

Reported by:MeehOwned by:zzz
Priority:
minor
Milestone:

Component:
apps/android
Version:
0.9.1
Keywords:

Cc:

Parent Tickets:

Sensitive:
no

Description

The android version is going to move host list from plaintext file to sqlite.

quick notes;

01:19:05 <@zzz> sure. Implement net.i2p.client.naming.NamingService? by extending net.i2p.client.naming.DummyNamingService?. Have at it.

01:20:30 <@zzz> once you're done, set the router config property i2p.naming.impl=my.full.class.name and it will use it.

01:21:11 <@zzz> on first instantiation, import from existing hosts.txt file into your db, see BlockfileNamingService? for clues

Subtickets

Opened [9 years ago](/timeline?from=2012-08-15T09%3A48%3A31Z&precision=second "See timeline at Aug 15, 2012 9:48:31 AM") Last modified [7 years ago](/timeline?from=2014-08-18T15%3A22%3A28Z&precision=second "See timeline at Aug 18, 2014 3:22:28 PM") ## [\#692](/ticket/692)[assigned](/query?status=assigned)[enhancement](/query?status=!closed&type=enhancement) # Moving hosts.txt to sqlite Reported by:[Meeh](/query?status=!closed&reporter=meeh)Owned by:[zzz](/query?status=!closed&owner=zzz) Priority: [minor](/query?status=!closed&priority=minor) Milestone: Component: [apps/android](/query?status=!closed&component=apps%2Fandroid) Version: [0.9.1](/query?status=!closed&version=0.9.1) Keywords: Cc: Parent Tickets: Sensitive: [no](/query?status=!closed&sensitive=0) ### Description The android version is going to move host list from plaintext file to sqlite. quick notes; 01:19:05 <@zzz> sure. Implement net.i2p.client.naming.NamingService? by extending net.i2p.client.naming.DummyNamingService?. Have at it. 01:20:30 <@zzz> once you're done, set the router config property i2p.naming.impl=my.full.class.name and it will use it. 01:21:11 <@zzz> on first instantiation, import from existing hosts.txt file into your db, see BlockfileNamingService? for clues ### Subtickets
idk added this to the undecided milestone 2025-04-21 14:45:25 -04:00
idk added the
#692
apps.android
labels 2025-04-21 14:45:25 -04:00
Author
Owner

comment:8 Changed 7 years ago by Meeh

Owner:
changed from Meeh to _zzz_Status:accepted →
assigned

Sorry but for now it seems lost. But ask me and I'll do it when I got

[comment:8](https://trac.i2p2.de/\#comment:8) Changed [7 years ago](https://trac.i2p2.de//timeline?from=2014-08-18T15%3A22%3A28Z&precision=second "See timeline at Aug 18, 2014 3:22:28 PM") by Meeh Owner: changed from _Meeh_ to _zzz_Status:accepted → assigned Sorry but for now it seems lost. But ask me and I'll do it when I got <time> (probably a while), or help if needed.
Author
Owner

comment:7 Changed 7 years ago by zzz

I briefly started implementing this. Do you still have your code? It would be helpful…

[comment:7](https://trac.i2p2.de/\#comment:7) Changed [7 years ago](https://trac.i2p2.de//timeline?from=2014-04-15T12%3A59%3A43Z&precision=second "See timeline at Apr 15, 2014 12:59:43 PM") by zzz I briefly started implementing this. Do you still have your code? It would be helpful…
Author
Owner

comment:6 Changed 9 years ago by zzz

Is a Service better? Maybe, maybe not. Like with ContentProvider?, you shouldn't use a Service just to get thread safety.

A service is like a background task, running independently of an Activity. The router, of course, is a Service. But why does the NamingService? need to be a service? Does it need to be doing something all the time? I doubt it - you look up a hostname, it either succeeds or fails… what else is there to do? And BTW, binding an Activity to a Service is a pain.

All you need for thread safety… where you need it… is of course synchronized(someLock) { … }. That's what I'm getting at. Understand what needs to be protected with a lock, if anything, and then code appropriately. Research whether your database is thread safe. If not, what's the best way?

BlockfileNamingService?, for example, just uses locking where necessary. Ditto with SingleFileNamingService?.

So again, I say: These Android constructions - ContentProvider?, Service, etc. - are there to be used for specific reasons. Not to provide magic thread safety. Maybe you need them. Maybe you don't. Maybe you're almost done implementing one. Maybe not. But I guarantee you that both of them are added complications.

[comment:6](https://trac.i2p2.de/\#comment:6) Changed [9 years ago](https://trac.i2p2.de//timeline?from=2012-08-17T21%3A05%3A10Z&precision=second "See timeline at Aug 17, 2012 9:05:10 PM") by zzz Is a Service better? Maybe, maybe not. Like with ContentProvider?, you shouldn't use a Service just to get thread safety. A service is like a background task, running independently of an Activity. The router, of course, is a Service. But why does the NamingService? need to be a service? Does it need to be doing something all the time? I doubt it - you look up a hostname, it either succeeds or fails… what else is there to do? And BTW, binding an Activity to a Service is a pain. All you need for thread safety… where you need it… is of course synchronized(someLock) { … }. That's what I'm getting at. Understand what needs to be protected with a lock, if anything, and then code appropriately. Research whether your database is thread safe. If not, what's the best way? BlockfileNamingService?, for example, just uses locking where necessary. Ditto with SingleFileNamingService?. So again, I say: These Android constructions - ContentProvider?, Service, etc. - are there to be used for specific reasons. Not to provide magic thread safety. Maybe you need them. Maybe you don't. Maybe you're almost done implementing one. Maybe not. But I guarantee you that both of them are added complications.
Author
Owner

comment:5 Changed 9 years ago by Meeh

Thanks for the guidelines and correction.

I've been reading a while now, and after some thinking I've changed my mind. I think it should only be instance working with the database. Now I'm looking more into a bound service, since it seems possible to make it threadsafe there. And that also make it possible to extend to a ContentProvider? later if needed for 3rdparty apps.

Also, I've read that when all "client/threads" disconnects from the service, the lifecycle will stop, so I researching if it need to be a service used with both onBind() by clients and onStartCommand(), that's starts & stops at the same time as the router.. The android documentation recommends a bound service when multiple components/threads will use it.

A service runs in the main thread of the application that hosts it, by default, so it would need a own thread too.

If I've got it right this will make it possible for both the router service and the addressbookactivity to access the resource at the same time. Also any other sub-threads, and a ContentProvider? if needed in the future. Do you think this sounds better?

refs:

​http://developer.android.com/guide/components/processes-and-threads.html#ThreadSafe

​http://developer.android.com/guide/components/bound-services.html#Lifecycle

​http://developer.android.com/guide/components/services.html

[comment:5](https://trac.i2p2.de/\#comment:5) Changed [9 years ago](https://trac.i2p2.de//timeline?from=2012-08-17T20%3A28%3A05Z&precision=second "See timeline at Aug 17, 2012 8:28:05 PM") by Meeh Thanks for the guidelines and correction. I've been reading a while now, and after some thinking I've changed my mind. I think it should only be instance working with the database. Now I'm looking more into a bound service, since it seems possible to make it threadsafe there. And that also make it possible to extend to a ContentProvider? later if needed for 3rdparty apps. Also, I've read that when all "client/threads" disconnects from the service, the lifecycle will stop, so I researching if it need to be a service used with both onBind() by clients and onStartCommand(), that's starts & stops at the same time as the router.. The android documentation recommends a bound service when multiple components/threads will use it. A service runs in the main thread of the application that hosts it, by default, so it would need a own thread too. If I've got it right this will make it possible for both the router service and the addressbookactivity to access the resource at the same time. Also any other sub-threads, and a ContentProvider? if needed in the future. Do you think this sounds better? refs: [​http://developer.android.com/guide/components/processes-and-threads.html#ThreadSafe](https://trac.i2p2.de/http://developer.android.com/guide/components/processes-and-threads.html#ThreadSafe) [​http://developer.android.com/guide/components/bound-services.html#Lifecycle](https://trac.i2p2.de/http://developer.android.com/guide/components/bound-services.html#Lifecycle) [​http://developer.android.com/guide/components/services.html](https://trac.i2p2.de/http://developer.android.com/guide/components/services.html)
Author
Owner

comment:4 Changed 9 years ago by zzz

I didn't say you shouldn't use a ContentProvider?. I said you did it for the wrong reason.

Doesn't sound like you have fully analyzed the locking requirements / thread safety for your database. That's what you have to get right - whether or not it's a ContentProvider?. Saying you just changed something (i.e. switched to a ContentProvider?) and now it works doesn't inspire confidence.

Where the ContentProvider? yes/no issue _is_ important is whether the DB should be available to other apps.

Where the ContentProvider? yes/no issue _might_ be important is with AddressbookActivity? - should it work when the router isn't running? Should there be multiple instances of the DB? If it's started before the router starts, should the router somehow grab the existing DB instance? See also the rather cheap shortcut I took on that issue at the top of AddressbookActivity?.

[comment:4](https://trac.i2p2.de/\#comment:4) Changed [9 years ago](https://trac.i2p2.de//timeline?from=2012-08-17T18%3A50%3A00Z&precision=second "See timeline at Aug 17, 2012 6:50:00 PM") by zzz I didn't say you shouldn't use a ContentProvider?. I said you did it for the wrong reason. Doesn't sound like you have fully analyzed the locking requirements / thread safety for your database. That's what you have to get right - whether or not it's a ContentProvider?. Saying you just changed something (i.e. switched to a ContentProvider?) and now it works doesn't inspire confidence. Where the ContentProvider? yes/no issue \_is\_ important is whether the DB should be available to other apps. Where the ContentProvider? yes/no issue \_might\_ be important is with AddressbookActivity? \- should it work when the router isn't running? Should there be multiple instances of the DB? If it's started before the router starts, should the router somehow grab the existing DB instance? See also the rather cheap shortcut I took on that issue at the top of AddressbookActivity?.
Author
Owner

comment:3 Changed 9 years ago by Meeh

I had some problems with database locking problems on the first try, so I gave it a try with ContentProvider? because that solved the locking problem. I see your points, but I'm a bit afraid that it could be a locking problem between the addressbook edit and router service, so I do it to be safe.

If you think it's a bad idea, I'll start over and do it your way, but I think this might be the right way to do it.

Anyway I'm finished with the importer, so when the database is called, it checks for entries, if it's emtpy it importing from hosts.txt.

[comment:3](https://trac.i2p2.de/\#comment:3) Changed [9 years ago](https://trac.i2p2.de//timeline?from=2012-08-17T17%3A03%3A04Z&precision=second "See timeline at Aug 17, 2012 5:03:04 PM") by Meeh I had some problems with database locking problems on the first try, so I gave it a try with ContentProvider? because that solved the locking problem. I see your points, but I'm a bit afraid that it could be a locking problem between the addressbook edit and router service, so I do it to be safe. If you think it's a bad idea, I'll start over and do it your way, but I think this might be the right way to do it. Anyway I'm finished with the importer, so when the database is called, it checks for entries, if it's emtpy it importing from hosts.txt.
Author
Owner

comment:2 Changed 9 years ago by zzz

ref: ​http://developer.android.com/guide/topics/providers/content-provider-creating.html and ​http://developer.android.com/guide/topics/data/data-storage.html#db

Everything is threaded. Not just I2P is threaded. Android is threaded. Java is threaded. Threading is not a reason to use a ContentProvider?. You only need a ContentProvider? to allow access to the DB from other apps.

Long-term, it would be great to provide that access to other apps - this is the equivalent of I2P applications outside the router's JVM (i.e. outside of RouterContext?) accessing the NamingService? on a PC platform - something that's problematic today.

But I don't think there is anything requiring you to start out by implementing a ContentProvider?… unless it's needed to get access from both the addressbook edit activity and the router service? Is that why you are doing it?

[comment:2](https://trac.i2p2.de/\#comment:2) Changed [9 years ago](https://trac.i2p2.de//timeline?from=2012-08-17T15%3A32%3A43Z&precision=second "See timeline at Aug 17, 2012 3:32:43 PM") by zzz ref: [​http://developer.android.com/guide/topics/providers/content-provider-creating.html](https://trac.i2p2.de/http://developer.android.com/guide/topics/providers/content-provider-creating.html) and [​http://developer.android.com/guide/topics/data/data-storage.html#db](https://trac.i2p2.de/http://developer.android.com/guide/topics/data/data-storage.html#db) Everything is threaded. Not just I2P is threaded. Android is threaded. Java is threaded. Threading is not a reason to use a ContentProvider?. You only need a ContentProvider? to allow access to the DB from other apps. Long-term, it would be great to provide that access to other apps - this is the equivalent of I2P applications outside the router's JVM (i.e. outside of RouterContext?) accessing the NamingService? on a PC platform - something that's problematic today. But I don't think there is anything requiring you to start out by implementing a ContentProvider?… unless it's needed to get access from both the addressbook edit activity and the router service? Is that why you are doing it?
Author
Owner

comment:1 Changed 9 years ago by Meeh

Status:new →
accepted

I've researched a bit on how to do this now. And the solution seems to be a ContentProvider? because i2p is threaded. (database locking etc.)

Status:

  • Finished with the database class & initial creation

  • I'm soon finished with a simple ContentProvider? for getting hosts, inserting, updating, deleting.

TODO

  • Read more about the classes zzz talk about, and how to implementate them.

  • Testing,Testing,Testing,Testing,Testing

  • Build a NamingService? querying the contentprovider instead of hosts.txt

I will not commit to mtn before this works.

[comment:1](https://trac.i2p2.de/\#comment:1) Changed [9 years ago](https://trac.i2p2.de//timeline?from=2012-08-15T09%3A52%3A52Z&precision=second "See timeline at Aug 15, 2012 9:52:52 AM") by Meeh Status:new → accepted I've researched a bit on how to do this now. And the solution seems to be a ContentProvider? because i2p is threaded. (database locking etc.) Status: - Finished with the database class & initial creation - I'm soon finished with a simple ContentProvider? for getting hosts, inserting, updating, deleting. TODO - Read more about the classes zzz talk about, and how to implementate them. - Testing,Testing,Testing,Testing,Testing - Build a NamingService? querying the contentprovider instead of hosts.txt I will not commit to mtn before this works.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: I2P_Developers/i2p.android.base#51
No description provided.