{"id":13743702,"url":"https://github.com/lava-tech/hls-p2p","last_synced_at":"2025-05-09T01:31:40.636Z","repository":{"id":30682581,"uuid":"34238457","full_name":"lava-tech/hls-p2p","owner":"lava-tech","description":"Flash OSMF based hybrid cdn\u0026p2p hls solution","archived":false,"fork":false,"pushed_at":"2016-05-06T09:18:55.000Z","size":3159,"stargazers_count":89,"open_issues_count":1,"forks_count":50,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-11-15T14:35:47.867Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"ActionScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lava-tech.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.txt","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-20T04:45:09.000Z","updated_at":"2023-11-04T06:07:04.000Z","dependencies_parsed_at":"2022-09-03T23:21:15.514Z","dependency_job_id":null,"html_url":"https://github.com/lava-tech/hls-p2p","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lava-tech%2Fhls-p2p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lava-tech%2Fhls-p2p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lava-tech%2Fhls-p2p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lava-tech%2Fhls-p2p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lava-tech","download_url":"https://codeload.github.com/lava-tech/hls-p2p/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253174350,"owners_count":21865850,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T05:00:55.249Z","updated_at":"2025-05-09T01:31:35.623Z","avatar_url":"https://github.com/lava-tech.png","language":"ActionScript","funding_links":[],"categories":["Networking"],"sub_categories":["P2P"],"readme":"# hls-p2p\nFlash OSMF based hybrid cdn\u0026amp;p2p hls solution. Currently it support LIVE hls. \nFlash support rtmfp protocal, we use that to deliver video\u0026audio data in p2p\u0026cdn hybrid way.\n\nNOTE: Please take some time to READ this file.\n\n# how it works\nWe use https://github.com/denivip/osmf-hls-plugin to enable hls support. Use that as a base, we developed the p2p part.\n\nNormally, for hls protocal, client download m3u8 first, then download ts; In our p2p solution, client download m3u8 from\nserver first, then download ts and m3u8 from server or other peers.\n\nWe developed a algorithm for LIVE hls P2P.\n\nThe algorithm is like this:\n* for a single ts file, if we download it from peer, we download it from more than one peer\n* we establish a p2p topology at first.\n* data is pushed from one peer to others\n* if one peer exits, downstream will know that after a while, and will PING the exited peer, \n  if PING fails, it will retry to establising a new topology. In the process of rebuilding the\n  new topology, data will be downloaded from server.\n* peer is considered as stable if it can be added to other peer's topology.\n* m3u8 is small, it will be downloaded only from one peer.\n\nServer part:\n  * P2P need a server to support rtmfp. we use https://github.com/OpenRTMFP/Cumulus.\n    Cumulus support lua, we can add peer id to redis using lua script.\n  * we also use redis to store peer ids.\n  * a nodejs http service for peer to find other peers' id.\n\nClient part:\n  * we implement a `P2PLoader`, which will replace the original `HTTPStreamDownloader` in osmf-hls-plugin\n\n# Install\n  * our test server is CentOS 6.2, you can `bash install/install_p2p.sh` to install required server software.\n  * The IDE we used to develope our flash code is 'FlashDevelop'\n\n# Run and test\nServer:\n  * start redis\n  * copy \"cumulus/main.lua\" to \"Cumulus/CumulusServer/www\" folder and start CumulusServer.\n    For how to set config for CumulusServer, refer to https://github.com/OpenRTMFP/Cumulus/wiki/Installation#configurations\n  * copy \"server/remote_log\" to any folder, under remote_log, run `npm install`, then `node index.js`\n  * you also need a media server to stream HLS(such as FMS, Wowza, or Lava Media Server 4(trochilus) if you interested).\n    note: Lava Media Server 4 is not a open source project now.\n\nClient:\n  * Build the binary. Note: because we use osmf source code directly, you need to remove default osmf lib in you computer\n    before building it.\n  * Change config in bin/index.html\n  ```\n  change the ip of your server in bin/index.html, such as \"115.29.205.140\"\n  ```\n  some config value and their meanings are as follows:\n  ```\n  # the url of LIVE hls stream, it MUST be live and single stream\n  # it should only contain ts file, and MUST NOT contain another m3u8 file\n  m3u8_url: \"http://211.103.128.226:8080/live/tvie/xray/pad.m3u8\",\n  # the rtmfp url\n  rtmfp_url: \"rtmfp://115.29.205.140:19350/app\",\n  # the url we will get peers information\n  http_tracker: \"http://115.29.205.140:5000/get_peers\",\n  # send log to that url\n  remote_log_base_url: \"http://115.29.205.140:5000/remote_log\",\n  # how many peers we will use to download data\n  rtmfp_url_peers: 2,\n  # leave it as it is\n  index_rtmfp_url: \"\",\n  # leave it as it is\n  index_rtmfp_url_peers: 1,\n  # the server ip and port from where we download m3u8 and ts.\n  # if you do not know how it works, set it as the same as `m3u8_url`\n  source_servers: [\"211.103.128.226:8080\"]\n  ```\n \n  * put bin/* under a web server(such as nginx).\n  * visit `bin/index.html` in your browser\n\n# Data\nIn Cumulus, we will add peer informations to redis.\nYou can get the peer informations in redis with following command\n\n* List all p2p instance.\n```\n127.0.0.1:6379 \u003e SMEMBERS cumulus_app\n```\n\n* For one p2p instance, get all connected peers' id. for example: if I want to get peers of a p2p instance called \"app\"\n```\n127.0.0.1:6379\u003e LLEN app\n(integer) 1\n127.0.0.1:6379\u003e LRANGE app 0 1\n1) \"c39e1de52e704279ecb6800bdb4c20006059d6b600b8abd08941a4119dc4250b\"\n```\n\n* For some debug reason, if you want to clear all peers of a p2p instance called \"app\", you can do\n```\n127.0.0.1:6379\u003e LTRIM app 0 0\n```\n\n# peer - server protocal\n* Flash client connect Cumulus using RTMFP protocal. Flash client will get a `peerID`(a unique id), and in `main.lua`,\n  we save client `peerID` to redis.\n* Flash client send http request to `remote_log` service to find other peer ids, so that it can connect other peer.\n* If user close the `index.html` page, the page will send `disconnect` event to `remote_log`, `remote_log` will remove that\n  peer's id from redis.(We need to do this because Flash in chrome will not send disconnect event to Cumulus server)\n\n# peers protocal\n* First, we need to create two way session between two peer, from each side it can send msg. We call it \"Create Session\"\n* We call one ts file as CHUNK. A CHUNK may contain more than one PIECE. We download one PIECE of CHUNK from different peer.\n* After we have connect ENOUGH peers, we send them HAS_CHUNK_REQ(ts_url) msg to query if we can download PIECE from them.\n* After enough peers send back us 'HAS_CHUNK_RESP(yes)', We send 'GET_PIECE_REQ(url, piece_id)' to qualified peers.\n* After we got some data of a CHUNK, we feed it to player.\n* If we do not get the CHUNK at required time, we will query if the peer still alive, if not, we call it \"P2P Failed\".\n* If we are in \"P2P Failed\", we will shift from \"P2P mode\" to \"CDN mode\".\n* If we are in \"CDN mode\", we will try to shift to \"P2P mode\" at intervals\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flava-tech%2Fhls-p2p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flava-tech%2Fhls-p2p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flava-tech%2Fhls-p2p/lists"}