Exemple #1
0
def peer_cache_report(protocol, host, port, peer_id, file_id, cppc, op):

    url = "/sdk/cache_report/v1"

    headers = HeaderData().Content__Type('application/json').ACCEPT('application/json').get_res()

    files = [
        {
            "file_id": file_id,
            "cppc": int(cppc),
            "op": op
        }
    ]

    body_data = {"peer_id": peer_id,
                 "files": files}

    response = send_request(
        '[TsPeerCacheReport]',
        protocol,
        POST,
        host,
        port,
        url,
        headers,
        None,
        body_data
    )
    return response
Exemple #2
0
def peer_download_flow(httporhttps, stats_host, stats_port, file_id, file_url, fsize, peer_id, flow_id, p2p=0,
                       file_type="live_flv"):

    url = "/sdk/flow/download/version/1"

    headers = HeaderData().Content__Type('application/json').ACCEPT('allication/json').get_res()

    timestamp = time.time()
    all_flow = 100000000
    httpdown = all_flow*(1-float(p2p))
    p2pDown = all_flow*float(p2p)

    flow = [
        {
            "timestamp": int(timestamp*1000),
            "duration": 60,
            "p2pDown": int(p2pDown),
            "httpDown": int(httpdown)
        }
    ]

    downloads = [
        {
            "url": str(file_url),
            "file_id": str(file_id),
            "fsize": int(fsize),
            "user_agent": "",
            "flow": flow
        }
    ]

    body_data = {
        "id": str(flow_id),
        "timestamp": int(timestamp),
        "type": str(file_type),
        "peer_id": str(peer_id),
        "downloads": downloads
    }

    response = send_request(
        '[PeerDownloadFlow]',
        httporhttps,
        POST,
        stats_host,
        stats_port,
        url,
        headers,
        None,
        body_data
    )

    return response
Exemple #3
0
def peer_login(protocol, host, port, peer_id, peer_body):

    url = "/session/peers/" + str(peer_id)

    headers = HeaderData().Content__Type('application/json').ACCEPT('application/json').get_res()

    body_data = peer_body

    response = send_request(
        '[TsPeerLogin]',
        protocol,
        POST,
        host,
        port,
        url,
        headers,
        None,
        body_data
    )
    return response
Exemple #4
0
def sdk_seed_flow(httporhttps, stats_host, stats_port, file_id, peer_id, upload, download, upload_conn, accept_conn,
                  denied_conn, flow_id, file_type="live"):

    url = "/sdk/seed/v1"

    headers = HeaderData().Content__Type('application/json').ACCEPT('allication/json').get_res()

    timestamp = time.time()

    flow = [
        {
            "file_id": str(file_id),
            "file_type": str(file_type),
            "upload": int(upload),
            "download": int(download)
        }
    ]

    body_data = {
        "id": str(flow_id),
        "timestamp": int(timestamp),
        "peer_id": str(peer_id),
        "upload_connections": int(upload_conn),
        "accept_connections": int(accept_conn),
        "denied_connections": int(denied_conn),
        "flow": flow
    }

    response = send_request(
        '[SdkSeedFlow]',
        httporhttps,
        POST,
        stats_host,
        stats_port,
        url,
        headers,
        None,
        body_data
    )

    return response
Exemple #5
0
def peer_live_progress(httporhttps, report_host, report_port, file_id, peer_id, chunk_id, file_type):

    url = "/live/" + str(file_id) + "/progress"
    headers = HeaderData().Content__Type('application/json').ACCEPT('application/json').get_res()
    body_data = {
        "timestamp": int(time.time()*1000),
        "peer_id": str(peer_id),
        "chunk_id": int(chunk_id),
        "type": str(file_type)
    }

    response = send_request(
        '[PeerLiveProgress]',
        httporhttps,
        POST,
        report_host,
        report_port,
        url,
        headers,
        None,
        body_data
    )
    return response