Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload for Profit #159

Open
wants to merge 226 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
226 commits
Select commit Hold shift + click to select a range
c9bfeef
Add boilerplate code for trustchain community
AlexDumitru17 Mar 19, 2023
d329780
Added an example of a trustchain transaction
AlexDumitru17 Mar 20, 2023
aed9c66
refactored community sim to prepare for multiple gossipers
ChrisSBras Mar 21, 2023
235706c
Merge remote-tracking branch 'origin/master' into 17-trustchain-commu…
AlexDumitru17 Mar 21, 2023
8d652f8
added bootgossiper framework
ChrisSBras Mar 21, 2023
0fb28c4
Merge branch 'master' into 6-extended-dummy-gossiper
ChrisSBras Mar 21, 2023
939b080
added setups for the other gossiper classes
ChrisSBras Mar 21, 2023
1e2202c
added max loops to bootgossiper
ChrisSBras Mar 25, 2023
c4770f0
Added trustchain proposal and response
AlexDumitru17 Mar 26, 2023
4584114
added message handlers
ChrisSBras Mar 26, 2023
37f173c
added bootresponse
ChrisSBras Mar 27, 2023
c3f4c2e
added link from bootgossip to networksizegossip
ChrisSBras Mar 27, 2023
0adc97e
handle bootresponse
ChrisSBras Mar 27, 2023
9ece8b2
moved torrent response to own file
ChrisSBras Mar 27, 2023
fd279a4
updated networksize gossiper
ChrisSBras Mar 27, 2023
8780c6b
added watchtime gossiper
ChrisSBras Mar 27, 2023
24971d6
added handler for watchtime messages
ChrisSBras Mar 27, 2023
172adfb
Set up a framework for strategies of recommender and yield predictïon
Floor97 Mar 28, 2023
8048c80
Started on xml for yield prediction
Floor97 Mar 28, 2023
7cfaf2e
fixed network estimate
ChrisSBras Mar 29, 2023
297a2da
Added video duration but it is not fully working yet
junojense Mar 29, 2023
f2c3b3f
Added list to spinners, and added bandwidth option to GUI
Floor97 Mar 29, 2023
69da05c
temp
ChrisSBras Mar 29, 2023
e704b59
Added duration, hop count and times seen, still untested, added funct…
junojense Mar 29, 2023
5b3667a
added measures to prevent exploding network size
ChrisSBras Mar 29, 2023
a78ab51
Hooked download and upload payload up to the upload gui and fixed con…
Floor97 Mar 31, 2023
dda93b1
Added maximum storage for seeding field, implemented methods to start…
Floor97 Apr 1, 2023
7f3bb7f
Fixed bugs in seeding strategy flow
Floor97 Apr 2, 2023
4049e63
Shows individual files in strategy screen
Floor97 Apr 3, 2023
2d07226
Fixed conflicts
Floor97 Apr 3, 2023
339dc93
Removed profile entry being a comparable
Floor97 Apr 3, 2023
2125543
Added more (dummy) fields and added a field for checking whether a vi…
twinkle-is-dum Apr 3, 2023
a3acd56
Fixed how upload date works (torrent creation date) and fixed a small…
junojense Apr 3, 2023
8ce9ee6
Merge pull request #32 from ChrisSBras/21-apply-yield-prediction
ChrisSBras Apr 5, 2023
d107c5a
Merge remote-tracking branch 'origin/development' into 17-trustchain-…
AlexDumitru17 Apr 5, 2023
132ddfd
Tidying the code
Floor97 Apr 5, 2023
a901133
Changed hash to file name, and filtered to only have one entry per hash
Floor97 Apr 5, 2023
5824db4
added base for new strategies
ChrisSBras Apr 5, 2023
021f2ba
Added a filter in the torrentgossiper to remove entries that can be null
junojense Apr 5, 2023
13aefb8
Forgot to add upload date in one spot
junojense Apr 5, 2023
9c190fb
updated strategies
ChrisSBras Apr 5, 2023
ca54db2
Merge branch 'development' into 6-extended-dummy-gossiper
ChrisSBras Apr 5, 2023
447ad5d
added divide by 2 in network gossiper
ChrisSBras Apr 5, 2023
4521331
Finalized values displayed in view, and changed the strategy_fragment…
Floor97 Apr 5, 2023
74c2777
Re-did the merge because I chose old implementation instead of new, i…
junojense Apr 6, 2023
f19acdf
Fixed some more feedback, made an attempt at removing clutter from log
junojense Apr 6, 2023
160fc67
Fixed the functions for (un)watched torrents to just use the profile …
junojense Apr 6, 2023
b6b1de8
Moved profile function, removed watched/unwatched functions as they a…
twinkle-is-dum Apr 7, 2023
e7661ec
Merge pull request #37 from ChrisSBras/21-apply-yield-prediction
Floor97 Apr 7, 2023
1662aa8
Fixed error on two unused vars
twinkle-is-dum Apr 7, 2023
8db6551
Refactored how we create profiles, removed the generate upload time a…
twinkle-is-dum Apr 7, 2023
bef2531
removed loop to check for mp4 files and now just increment if we have…
twinkle-is-dum Apr 7, 2023
1bdd4be
Added a check that there need to be more leechers than seeders to see…
Floor97 Apr 9, 2023
b72b5a4
Added loop that rechecks best strategy according to the SEEDING_LOOP_…
Floor97 Apr 9, 2023
24a2e15
Fixed bugs, set timeouts, call status() less often
Floor97 Apr 9, 2023
856756c
Merge pull request #36 from ChrisSBras/6-extended-dummy-gossiper
ChrisSBras Apr 10, 2023
2e5ce7e
Merge pull request #39 from ChrisSBras/35-optimization-for-seeding-st…
Floor97 Apr 10, 2023
f499b41
Added check if profile exists to torrent gossiper, removed a line of …
junojense Apr 10, 2023
216f3a6
Copy pasting code is bad practice
junojense Apr 10, 2023
e474ac6
Merge branch 'development' of https://github.com/ChrisSBras/trustchai…
Floor97 Apr 10, 2023
5a3346b
Update torrent gossiper by suggestion
junojense Apr 10, 2023
5a3e5e4
removed redundant method
twinkle-is-dum Apr 10, 2023
c60e89e
fixed var not being used
twinkle-is-dum Apr 10, 2023
9739402
Merge pull request #34 from ChrisSBras/23-profile-metrics
Floor97 Apr 10, 2023
487df6e
Merged master into dev to add the duration implementation
twinkle-is-dum Apr 10, 2023
744242a
Fixed feedback
twinkle-is-dum Apr 10, 2023
d7c311f
Merge pull request #42 from ChrisSBras/38-fix-the-duration-in-develop…
Floor97 Apr 10, 2023
b65c43d
Merge remote-tracking branch 'origin/development' into 17-trustchain-…
AlexDumitru17 Apr 10, 2023
a339293
added option to request money for seeding
AlexDumitru17 Apr 10, 2023
6bb760e
Added basic torrent debug screen
ChelseaGuan Apr 11, 2023
ff05bdf
Merge branch 'development' into 30-implement-strategies
ChrisSBras Apr 12, 2023
1136ce9
added new strategies
ChrisSBras Apr 12, 2023
344f83a
added hot
ChrisSBras Apr 12, 2023
d93fe71
Refactored the watch time gossiper to a profile entry gossiper and ad…
junojense Apr 12, 2023
ba23caa
unwatched videos are served first, seed_mode is changed to share_mode…
Floor97 Apr 13, 2023
d0ba673
Fixed unwatchedIndex to be the list size when no video is unwatched r…
Floor97 Apr 13, 2023
8808dc5
Fixed merge conflicts
Floor97 Apr 13, 2023
a90d868
updated seeding strategies
ChrisSBras Apr 13, 2023
078c4f4
added basic readme outline
ChrisSBras Apr 14, 2023
a406eb0
added more todo
ChrisSBras Apr 14, 2023
da356c9
added link to strategy
ChrisSBras Apr 14, 2023
2779cd6
Merge branch 'Tribler:master' into detoks_readme
ChrisSBras Apr 14, 2023
16ba8c7
Merge pull request #43 from ChrisSBras/41-final-additions-for-leechin…
Floor97 Apr 14, 2023
28cb6e3
Added a merge function to merge a received profile entry from the gos…
junojense Apr 14, 2023
5e1bd0a
added hopcount strategy
ChrisSBras Apr 14, 2023
7384679
Likes are now based on whether we only saw the value through gossipin…
junojense Apr 14, 2023
9b03272
Formatting and comments
junojense Apr 14, 2023
20c8a58
If we have not seen the torrent, last update is set to the highest ti…
junojense Apr 14, 2023
3456124
updated hot and rising strategy to include cutoff comparators
ChrisSBras Apr 14, 2023
7bdbb8a
hot and rising now use watchtime sorting
ChrisSBras Apr 14, 2023
9f97207
Changed the likes to an average instead
junojense Apr 14, 2023
3a34737
Removed redundant field
junojense Apr 14, 2023
c486d46
Added info hash, magnet link and bytes downloaded to torrent debug sc…
ChelseaGuan Apr 14, 2023
3d0d0b9
rising and hot first use cutoff filters to split into 2 lists, after …
ChrisSBras Apr 14, 2023
9cb9b0b
Changed watch time to likes, removed redundant variable
junojense Apr 14, 2023
2e5a7f2
added generic cutoff filter
ChrisSBras Apr 14, 2023
d25bd94
Actually assign the variable in addprofile
junojense Apr 14, 2023
7ac6a72
working on sending tokens for seeding
AlexDumitru17 Apr 14, 2023
0cf6571
Merge remote-tracking branch 'origin/development' into 28-torrent-deb…
ChelseaGuan Apr 15, 2023
425e5f8
Added watch time and hop count to torrent debug screen
ChelseaGuan Apr 15, 2023
2d7cceb
Updated the main, gossiping, and strategies sectons in the readme
Floor97 Apr 17, 2023
1448c5a
Added other profile stats to torrent debug screen
ChelseaGuan Apr 18, 2023
cac580d
decreased font size
ChelseaGuan Apr 18, 2023
d1b9b3f
Update README.md
ChelseaGuan Apr 18, 2023
4ef7be9
slight refactor
ChrisSBras Apr 18, 2023
64be39d
moved strategies around
ChrisSBras Apr 18, 2023
7c29977
dynamically obtain torrent name from the view
ChelseaGuan Apr 18, 2023
5a8afc9
removed hardcoded strings in TorrentFragment
ChelseaGuan Apr 18, 2023
d4f04b4
removed double sort
ChrisSBras Apr 18, 2023
7bdab67
Division by one instead of likes
junojense Apr 18, 2023
e3489d1
fixed merge conflict
ChrisSBras Apr 18, 2023
242edc4
Update README.md
junojense Apr 18, 2023
4ce71e5
changed time to milliseconds instead o seconds
ChrisSBras Apr 18, 2023
dd6100f
Merge pull request #44 from ChrisSBras/30-implement-strategies
ChrisSBras Apr 18, 2023
8e238a3
Best effort profile entry exchange, I use a msg per entry shared, in …
twinkle-is-dum Apr 18, 2023
45f23cc
Update README.md
junojense Apr 18, 2023
379841e
Merge pull request #45 from ChrisSBras/40-change-the-watchtime-gossip…
ChrisSBras Apr 18, 2023
063dd98
bound cacheend to size of torrentfiles
ChrisSBras Apr 18, 2023
5ef2b6f
better fix
ChrisSBras Apr 19, 2023
660d56b
Merge pull request #47 from ChrisSBras/hotfix/leechingstrategy_crash
ChrisSBras Apr 19, 2023
e82f4d0
made debug screen update in real-time
ChelseaGuan Apr 19, 2023
598500f
made it so that clicking on a video name also brings one to the debug…
ChelseaGuan Apr 19, 2023
6d542fc
fixed "Fragment not attached to a context" bug
ChelseaGuan Apr 19, 2023
5e596d2
fixed 0-division error
ChrisSBras Apr 19, 2023
b50e635
Merge pull request #46 from ChrisSBras/28-torrent-debug-screen
ChrisSBras Apr 19, 2023
50442ce
Finished coupling transactions to seeding/downloading
AlexDumitru17 Apr 19, 2023
9d50ec0
Merge remote-tracking branch 'origin/development' into 17-trustchain-…
AlexDumitru17 Apr 19, 2023
fe693a5
Changed amount type to float
AlexDumitru17 Apr 19, 2023
9fed320
Fixed checkstyle and comments
AlexDumitru17 Apr 20, 2023
c79a216
fixed profile reference with magnetlink bug
Floor97 Apr 20, 2023
9cdf7c9
Update README.md
ChelseaGuan Apr 20, 2023
9d309a9
Added general docs to general readme
Floor97 Apr 20, 2023
044b129
Merge branch 'detoks_readme' of https://github.com/ChrisSBras/trustch…
Floor97 Apr 20, 2023
51a9914
Added token readme
AlexDumitru17 Apr 20, 2023
81fa74b
Merge branch 'detoks_readme' of https://github.com/ChrisSBras/trustch…
Floor97 Apr 20, 2023
d44bea4
Update README.md
Floor97 Apr 20, 2023
dc941bd
Update README.md
Floor97 Apr 20, 2023
9a6e5ae
Update README.md
ChelseaGuan Apr 20, 2023
cba67d5
Update README.md
ChelseaGuan Apr 20, 2023
6a7a1b9
magnet link no longer falls off the screen
Floor97 Apr 20, 2023
b1e0537
fixed strategy sorting
ChrisSBras Apr 20, 2023
db3a43e
Merge pull request #49 from ChrisSBras/magnet_link_falls_off
ChelseaGuan Apr 20, 2023
5f16645
Merge pull request #48 from ChrisSBras/17-trustchain-community-with-d…
Floor97 Apr 20, 2023
444e67a
Update README.md
Floor97 Apr 20, 2023
576b5bf
Update README.md
Floor97 Apr 20, 2023
9cbb0de
Update README.md
Floor97 Apr 20, 2023
ce0e50c
Update README.md
Floor97 Apr 20, 2023
ed91199
Update README.md
ChelseaGuan Apr 20, 2023
0f835d7
Update README.md
ChelseaGuan Apr 20, 2023
c3bebd0
Fixed synchronization bug for seeding torrents
Floor97 Apr 20, 2023
4f61e7e
Fixed file not existing bug
Floor97 Apr 20, 2023
8779395
Merge pull request #52 from ChrisSBras/synchronization-bug
ChrisSBras Apr 20, 2023
0dc0093
Merge pull request #53 from ChrisSBras/detoks_readme
ChrisSBras Apr 20, 2023
2ceafb4
Merge pull request #50 from ChrisSBras/development
ChrisSBras Apr 20, 2023
c8c3027
Implemented fancy loading bar
Floor97 Apr 23, 2023
75ac777
changed seeding to be true by default and added download state
AlexDumitru17 Apr 25, 2023
0bdb1b7
Merged the torrent and profile entry gossipers and removed the profil…
junojense Apr 25, 2023
380a82b
added simple profile generator
ChrisSBras Apr 25, 2023
d9c86fb
Merge branch 'development' into 40-change-the-watchtime-gossiper-to-a…
junojense Apr 25, 2023
f6adfb9
Merge pull request #59 from ChrisSBras/40-change-the-watchtime-gossip…
ChrisSBras Apr 28, 2023
32a931a
removed other gossipers and now spawn nodes from node config
ChrisSBras May 1, 2023
d380bac
Merge branch 'master' into 54-dummy-upgrade
ChrisSBras May 1, 2023
b6412f5
Finalised loading bar
Floor97 May 1, 2023
f110160
Merge branch 'development' into 54-dummy-upgrade
ChrisSBras May 1, 2023
ef38cbd
added updated message serializtion and added profiles to torrent message
ChrisSBras May 1, 2023
c378d40
slight bugfixes
ChrisSBras May 1, 2023
6ddca62
Add seedRank statistic and fixed UI bug
AlexDumitru17 May 1, 2023
fe98f0b
created general debug screen
ChelseaGuan May 1, 2023
485ec5e
set networkmode host
ChrisSBras May 1, 2023
ae74a2b
fixed bug
ChelseaGuan May 1, 2023
fd68496
Fixed some things but it needs to do each video per torrent
junojense May 1, 2023
8e8b385
As far as I know we now use the filename of the video consistently ev…
junojense May 2, 2023
fe45b58
Checked all usages of where addprofile(key: String) is called and mad…
junojense May 2, 2023
224dd91
Actually removed debug msg
junojense May 2, 2023
2716ff8
Added basic debug tab
AlexDumitru17 May 2, 2023
be2c8a0
implemented metrics to show in general debug screen
ChelseaGuan May 2, 2023
2baac06
Update README.md
ChelseaGuan May 2, 2023
f0cbc09
added profit per torrent
AlexDumitru17 May 3, 2023
3ac3977
Merge pull request #60 from ChrisSBras/57-fancy-loading-bar
Floor97 May 3, 2023
8d54312
Changed argument of createkey to hash instead of magnet and updated r…
junojense May 3, 2023
f1ab853
added strategy descriptions
ChelseaGuan May 3, 2023
369a875
fixed typos
ChrisSBras May 3, 2023
c61bd26
added strategy descriptions
ChelseaGuan May 3, 2023
33027cd
Optimised the way the hashes are obtained for when createKey() is inv…
junojense May 3, 2023
674f173
Merge branch 'development' into 25-debug-screen
ChelseaGuan May 3, 2023
19b132d
Removed the function that takes a string and made it so that we use t…
junojense May 3, 2023
c1b7a7a
deleted comments
AlexDumitru17 May 3, 2023
e82c9ca
Merge pull request #62 from ChrisSBras/55-make-the-profile-entries-al…
junojense May 3, 2023
5f46296
updated dummy nodes to include index of file
ChrisSBras May 3, 2023
c2c55b9
made it so that there is no delay when the debug screen is first loaded
ChelseaGuan May 3, 2023
b39fd9d
Merge remote-tracking branch 'origin/25-debug-screen' into 25-debug-s…
ChelseaGuan May 3, 2023
a9bb4cc
Merge pull request #65 from ChrisSBras/25-debug-screen
ChelseaGuan May 3, 2023
7e91213
Merge pull request #61 from ChrisSBras/54-dummy-upgrade
ChrisSBras May 3, 2023
29227a8
Merge pull request #64 from ChrisSBras/56-make-extra-debug-informatio…
AlexDumitru17 May 3, 2023
907ac20
merged develop into master
ChrisSBras May 3, 2023
0ba3dc7
Update README.md
ChelseaGuan May 3, 2023
2a8f14b
readded bracket
ChrisSBras May 3, 2023
973fc4c
merged upstream
ChrisSBras May 3, 2023
b9008f6
Moved createKey to companion object and let it function as stringbuil…
junojense May 3, 2023
9e8e62f
Cleaned code
Floor97 May 3, 2023
3a52534
Fixed conflicts
Floor97 May 3, 2023
1a4c679
Cleaned code
Floor97 May 3, 2023
7f0167f
Cleaned code and fixed bug
Floor97 May 3, 2023
e78903d
Merge pull request #66 from ChrisSBras/development
ChrisSBras May 3, 2023
bc692c2
Fixed conversion error
Floor97 May 3, 2023
a8af900
Fixed bugs in video screen
Floor97 May 4, 2023
dbda021
removed torrent files
Floor97 May 4, 2023
fbec3bd
added torrent files
Floor97 May 4, 2023
6e2888c
Resolved conflicts
Floor97 May 4, 2023
a80242d
Merge pull request #67 from ChrisSBras/development
ChrisSBras May 4, 2023
50224b5
fixed bug where top 3 leeching torrents do not display
ChelseaGuan May 4, 2023
195b9c3
Merge remote-tracking branch 'origin/development' into development
ChelseaGuan May 4, 2023
b926744
Merge pull request #68 from ChrisSBras/development
ChelseaGuan May 4, 2023
d2979ec
Update README.md
ChelseaGuan May 4, 2023
6220710
Update README.md
ChelseaGuan May 4, 2023
e1d0b66
changed date format
ChelseaGuan May 4, 2023
ecc1acb
deleted unused method
AlexDumitru17 May 4, 2023
6674cfa
Update README.md
ChelseaGuan May 4, 2023
599c093
Update README.md
junojense May 4, 2023
d43bb2c
Update README.md
junojense May 4, 2023
9fbdd3b
Fixed synchronization bug
Floor97 May 4, 2023
6777d52
Added all torrents
Floor97 May 4, 2023
01875a3
Removed all torrents
Floor97 May 4, 2023
988f004
Merge pull request #70 from ChrisSBras/detoks_readme
Floor97 May 4, 2023
e4879c2
Update README.md
junojense May 5, 2023
763f1f0
Update README.md
junojense May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ An online indicator and the last message is shown for each contact. Users can ex
### DeToks
**Decentralised TikTok** skeleton app for the CS4160 Blockchain Engineering (2022/23) course.


The aim of DeToks is to be the decentralised version of the famous TikTok app. When leeching users pay tokens, and when seeding they gain tokens.

The user can watch videos on the main screen and can swipe up or down, to go forwards or backwards in the videos. Whenever a video has not been downloaded yet, the user is presented with a loading screen displaying the download status and a loading bar. The videos are shown according to the leeching strategy that the user can select in the settings screen. The user can also enable seeding, in which case videos are downloaded according to the selected seeding strategy so that they can then be seeded. Additional torrenting statistics can be seen in the debug screen accessed through the settings. From the main screen displaying the video the statistics of the video can be viewed in the video statistics screen by pressing debug.

![demo-smallest](https://user-images.githubusercontent.com/31625452/236405398-5f2dcad4-1394-4929-afcd-ebb2204301a2.gif)

More documentation on the DeToks app can be found [here](https://github.com/ChrisSBras/trustchain-superapp/blob/master/detoks/README.md).

### Digital Euro

The Superapp is connected to the European IBAN Euro system.
Expand Down Expand Up @@ -197,6 +206,7 @@ Sharing, storing, and searching of scientific publications through the p2p ipv8

[More about literature dao app](literaturedao/README.md)


### Do you want to add your own app?

- [Adding your own app to the TrustChain Super App](doc/AppTutorial.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ class TrustChainApplication : Application() {

private fun createDeToksCommunity(): OverlayConfiguration<DeToksCommunity> {
val randomWalk = RandomWalk.Factory()

return OverlayConfiguration(
DeToksCommunity.Factory(this),
listOf(randomWalk)
Expand Down
137 changes: 137 additions & 0 deletions detoks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# DeToks

This document describes the functionallity provided in DeToks. Currently it contains the following functionality:
* Watch videos that are shared via the DeToks Community.
* Select a strategy with which to determine which video is played next.
* Option to seed videos for token profit based on a selected seeding strategy, maximum storage size and maximum upload bandwidth.
* View torrent information and statistics of seeded torrents.

![core-functionality](https://user-images.githubusercontent.com/31625452/236310196-38465bbc-0471-4c91-9da3-ed5eda8492a2.gif)

Click [here](https://twinkle.aaw.ooo/y73u8h7m55wap2tgy9rt.gif) for a higher definition GIF.

## Gossiping

A Large part of the DeToks back-end depends on information being gossiped over the DeToks community network. Gossiping works by selecting a random subset of all known peers of a node and passing messages between them. Since different kinds of data is shared, several gossipers are used. Namely:
* [BootGossiper](./src/main/java/nl/tudelft/trustchain/detoks/gossiper/BootGossiper.kt): gossips boot related data.
* [NetworkSizeGossiper](./src/main/java/nl/tudelft/trustchain/detoks/gossiper/NetworkSizeGossiper.kt): estimates network size.
* [TorrentGossiper](./src/main/java/nl/tudelft/trustchain/detoks/gossiper/TorrentGossiper.kt): gossips torrents and corresponding profile metrics.

All of these extend `Gossiper`. This section gives short descriptions of each of them.

### BootGossiper

The [BootGossiper Class](./src/main/java/nl/tudelft/trustchain/detoks/gossiper/BootGossiper.kt) is used to bootstrap the session when starting up the app. The app mainly uses this to bootstrap the networksize value, which then is further kept up to date by the [NetworkSizeGossiper](#NetworkSizeGossiper).

The network size specifically is requested on boot because it plays an important role in determining the size of the other metrics. For example, the total watch time and total likes on a video are determined using this value.

### NetworkSizeGossiper

The [NetworkSizeGossiper Class](./src/main/java/nl/tudelft/trustchain/detoks/gossiper/NetworkSizeGossiper.kt) is used to estimate the current total size of the DeToks community network. This is done by utilizing the count algorithm as described in [Gossip-Based Aggregation in Large Dynamic Networks](https://dl-acm-org.tudelft.idm.oclc.org/doi/pdf/10.1145/1082469.1082470).

### TorrentGossiper

The [TorrentGossiper Class](./src/main/java/nl/tudelft/trustchain/detoks/gossiper/TorrentGossiper.kt) is used to spread torrent files throughout the network. A random subset of torrents is selected and then sent to a random subset of peers. This happens every few seconds to ensure a good spread of torrents throughout the network.

Next to the torrent, this class also distributes profile statistics throughout the network. Some of these are incorporated in one of the leeching and seeding strategies. This is used to update peers on the profile data it has for a specific video. Furthermore, some of these statistics are also used for the for debugging.

Together with the key and associated magnet link of the profile the shared metrics are:
* `hopCount`: incremented on sending, this statistic details how many hops a torrent was shared from its origin.
* `watchTime`: when received, update the average watch time of torrent on the network.
* `duration`: when received, set duration of torrent if it was unknown.
* `uploadDate`: when received, set upload date of torrent if it was unknown.
* `likes`: when received, update the estimated likes of torrent on the network.

## Profiles

The [Profile](./src/main/java/nl/tudelft/trustchain/detoks/Profile.kt) class is used to store a certain set of metrics in a profile entry for each torrent. Useful metadata is stored in these entries that help the other parts of DeToks with choosing which torrents to seed, leech and recommend to the user. Each node within the network has their own aggregate of profile entries, their profile. This section describes stored parameters in the profile entries. Entries are added to the profile when either a new torrent is received, or if an entry is shared through gossiping. Almost all values are initialised to zero. The exception is the *watched* field, which is initialised to *false*. The class also contains some auxilliary functions for updating parameters.

* `watched`: set to true if a video of the torrent was watched.
* `watchTime`: average watch time of torrent on the network.
* `duration`: the duration of the first watched video in the torrent.
* `uploadDate`: the creation date of the torrent.
* `hopCount`: the amount of hops the torrent made over the network.
* `timesSeen`: the amount of times this node has received the same torrent.
* `likes`: the amount of likes, this is currently a stub and depends on the implementation of another team.

## Strategies

The user can specify a leeching and optionally also a seeding strategy. The user can pick the same strategies for leeching and seeding, as both need the torrents to be sorted based on profile metrics. However, the leeching strategy determines which videos are played for the user in the video screen, while the seeding strategy determines in which way the torrents are sorted to be considered for seeding.

### Defined Strategies
The available strategies are defined in [Strategy.kt](./src/main/java/nl/tudelft/trustchain/detoks/Strategy.kt), and include:
* `STRATEGY_RANDOM`: The random strategy simply chooses torrents to seed at random.
* `STRATEGY_HIGHEST_WATCH_TIME`: This strategy sorts the torrents by watchtime in descending order.
* `STRATEGY_LOWEST_WATCH_TIME`: This strategy sorts the torrents by watchtime in ascending order.
* `STRATEGY_HOT`: This strategy splits the torrents into two lists based on a time cut-off, and sorts both lists by watchtime in descending order. These lists are then merged again, where the list under the cut-off is added in front.
* `STRATEGY_RISING`: This strategy is the same as `HOT_STRATEGY`, but the time cut-off is lower.
* `STRATEGY_NEW`: This strategy sorts the torrents by upload date from newest to oldest.
* `STRATEGY_TOP`: This strategy sorts torrents by number of likes in descending order.
* `STRATEGY_HOPCOUNT`: This strategy sorts the torrents by hopcount in descending order.

### Leeching

As previously mentioned, the leeching strategy determines which videos are played for the user. This happens by applying the strategy to the specific unwatched part of the available torrents. To do so, an index is kept track of that specifies until where the user has watched. When a new torrent is received, this is inserted into the right place in that part of the list as well. If the user has watched all of its known torrents, the entire list will be sorted instead.

### Seeding

A user can seed torrents to earn tokens on the DeToks community network. This option can be turned on in the Settings view:

<img src="https://user-images.githubusercontent.com/57201085/236303160-d3001371-45de-4356-8a94-710b52e5469f.jpg" alt="seeding" width="25%">

The user has to specify:
* Maximum bandwidth per day (in MB): sets the maximum upload rate.
* Maximum storage used for seeding (in MB): sets the maximum accumulated size of all seeded torrents combined after download.
* Seeding strategy: the default is `STRATEGY_RANDOM` but other strategies can be selected. Used to sort the torrents for consideration of seeding.

The seeded torrents will then be shown to the user in the overview below. For a seeded torrent the name, total amount downloaded in a session (in MB), total amount uploaded in a session (in MB), and balance of earned tokens for seeding that torrent in this session is shown.

The seeding strategy only sorts the torrents into a list of torrents that will be considered for seeding. In order for a video to be seeded it needs to have more leechers than seeders, and then it will only be selected if it doesn't push the size of the selected torrents over the maximum storage threshold. When it is selected it will attempt to download the torrent with a timeout. If the download is successful, the `SHARE_MODE` flag of the torrent will be turned on, completing the process.

## Tokens

A simple token transaction implementation was added in order to test if transactions can be performed while seeding and downloading. Whenever an user finishes downloading a piece of the torrent they are downloading, they send a token to the peers which were seeding it. We check for that by using the alert `AlertType.PIECE_FINISHED`, and we identify the peers that were seeding the downloaded piece based on the information given by the current torrent handle. In addition, peers may also seed torrents to peers outside of the DeToks Community, by which they also get compsated by increasing their wallet balance.

## Debug Screens

### Torrent-Specific Debug Screen
A user may access the debug screen for a specific torrent by clicking on the name of the video in the main DeToks screen or by clicking on its name in the list of seeded torrents shown in [Seeding](#seeding).
<img src="https://user-images.githubusercontent.com/57201085/236295625-a4113632-3393-46cc-994d-ffe079ba04cf.jpg" width="25%">

It displays libtorrent metadata on the torrent such as:
* `infoHash`: info hash of the torrent.
* `magnetLink`: magnet link of the torrent.
* `files`: list of files that are contained in the torrent.
* `downloadedBytes`: total number of bytes that have been downloaded from the torrent since it started.

It also displays torrent profile metrics as mentioned in [TorrentGossiper](#torrentgossiper):
* `watchTime`
* `hopCount`
* `duration`
* `timesSeen`
* `uploadDate`

and two extra profile metrics:

* `watched`: whether or not the video was watched
* `likes`: number of likes that the torrent has

### Global Debug Screen
A user may access the general debug screen by clicking on the "Debug" button.

<img src="https://user-images.githubusercontent.com/57201085/236295401-33e4fa3b-4875-4221-b06b-fe57c58df32f.jpg" alt="general debug screen" width="25%">

It displays information on such as:
* `Estimated networksize`: estimated number of peers in the network.
* `Number of connected peers`: number of connected peers.
* `List of connected peer`: peer IDs (mid) of the connected peers.
* `Top 3 leeching torrents`: torrent names of the top 3 leeching torrents with a description of the leeching strategy.
* `Top 3 seeding torrents with metrics from seeders`: torrent names of the top 3 seeding torrents with a description of the seeding strategy.
* `Seeding status`: whether or not the peer is seeding.
* `Wallet token amount`: amount of tokens in a peer's wallet.
* `Peer ID`: mid of my peer.

### Seeding Debug Screens
We also created a screen with more details on seeding torrents accessible by clicking the "Torrent Infos" button in Settings.
<img src="https://user-images.githubusercontent.com/57201085/236297098-87829223-0a22-4c79-862c-9e729ec7d3a7.jpg" alt="seeding debug screen" width="25%">

Loading