From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 79E2A4081C for ; Mon, 31 Jan 2022 16:06:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4496068B10A; Mon, 31 Jan 2022 18:06:29 +0200 (EET) Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 84C4F68B025 for ; Mon, 31 Jan 2022 18:06:23 +0200 (EET) Received: by mail-oi1-f176.google.com with SMTP id q186so27499925oih.8 for ; Mon, 31 Jan 2022 08:06:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:content-language:to :references:from:subject:in-reply-to:content-transfer-encoding; bh=LjSqj7CIFsCku4fN9Z2XPk/z2xNmVZIhGhM/hmEIoD4=; b=ng4g5jmSRZWP5bexMHwRcaikSXrjsj00qJ3PZ7h864oYOVEpGDfWTQqM7IGItmyDml 9QDboa2xP3R2ZT1SLnKGQ8qL2RUEjhXLynz6IseVvmbOdWjcfJxpPkxviaEJ/R1eTo1p 2nW3cB5eqNP2wk35oAgr8j0ACgemyp3qke8QEG4acd2Va+xqaVMjX0xKtpxI9bRIEr3y vqeSHgey3kxWAHoq2JOfdquuUSKIwIlYV2cDgnilGiIyBSY3c7RXSioNq+XdNffiC2Eg 3vtf6+DxQItRZfX1JThfDZgzhmdBufX19NHDhFcG+nz5TnRpxw8B3N31u0yuBJy4VkRq UQTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:references:from:subject:in-reply-to :content-transfer-encoding; bh=LjSqj7CIFsCku4fN9Z2XPk/z2xNmVZIhGhM/hmEIoD4=; b=4sIrDDPCQ62udKDxe2K6Qs9dtSmu/tgiVkBx/YVY6ADghzQnZqKN93ubJSj+i80pNi t9ASmOjqLbuWweaSpSxPM3xOHtWLBwTr+PmbOioMzHe6ebQpksI3bCvP6Hj0i3WEWnTv NO+IJT/BgRSSeSSp98jnntAI6cAf3GQ4kt7GFjuaYvY74adNNmbX9SWa1L/AapWRLZGB m4Eq4jRM9F10E2AcROv2RJRfwYAbKOYCmPdf8nxObnz70kxqGMKwBCPFrXInQ9aB/DSP ifGI94UcV15/wxf3ydkysj4SItFvHKFobRQ92UwhkYZFqxPuFKhdtPzViWe8GU/PdG5J eLZQ== X-Gm-Message-State: AOAM532eNHttEzQ5qUeoOJFepKMwt0VO50FY8il061ocnG3GkU/II9RX J7rsqkKlmxEkB9L2yunxTXCnIsCn9QI= X-Google-Smtp-Source: ABdhPJw5fVhd5FatNRWGMmCWuL9W/6ZSFCgq097/c3irvWbXMafRWQPf24n7G9xWNMlZzrW90s9Ihg== X-Received: by 2002:a05:6808:a06:: with SMTP id n6mr14401446oij.45.1643645181464; Mon, 31 Jan 2022 08:06:21 -0800 (PST) Received: from [192.168.0.10] ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id n67sm9266434oib.31.2022.01.31.08.06.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Jan 2022 08:06:21 -0800 (PST) Message-ID: <0a7f2b72-ddfa-2854-b87d-def414df5b85@gmail.com> Date: Mon, 31 Jan 2022 13:06:19 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20220131135116.14035-1-markg85@gmail.com> <20220131135116.14035-2-markg85@gmail.com> From: James Almer In-Reply-To: <20220131135116.14035-2-markg85@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH 1/5] Early version of IPFS protocol support. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 1/31/2022 10:51 AM, Mark Gaiser wrote: > Signed-off-by: Mark Gaiser > --- > configure | 1 + > doc/protocols.texi | 30 ++++++ > libavformat/Makefile | 1 + > libavformat/ipfs.c | 202 ++++++++++++++++++++++++++++++++++++++++ > libavformat/protocols.c | 2 + > 5 files changed, 236 insertions(+) > create mode 100644 libavformat/ipfs.c > > diff --git a/configure b/configure > index 5b19a35f59..e466f924a3 100755 > --- a/configure > +++ b/configure > @@ -3585,6 +3585,7 @@ udp_protocol_select="network" > udplite_protocol_select="network" > unix_protocol_deps="sys_un_h" > unix_protocol_select="network" > +ipfs_protocol_select="https_protocol" > > # external library protocols > libamqp_protocol_deps="librabbitmq" > diff --git a/doc/protocols.texi b/doc/protocols.texi > index d207df0b52..7c9c0a4808 100644 > --- a/doc/protocols.texi > +++ b/doc/protocols.texi > @@ -2025,5 +2025,35 @@ decoding errors. > > @end table > > +@section ipfs > + > +InterPlanetary File System (IPFS) protocol support. One can access files stored > +on the IPFS network through so called gateways. Those are http(s) endpoints. > +This protocol wraps the IPFS native protocols (ipfs:// and ipns://) to be send > +to such a gateway. Users can (and should) host their own node which means this > +protocol will use your local machine gateway to access files on the IPFS network. > + > +If a user doesn't have a node of their own then the public gateway dweb.link is > +used by default. > + > +You can use this protocol in 2 ways. Using IPFS: > +@example > +ffplay ipfs://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T > +@end example > + > +Or the IPNS protocol (IPNS is mutable IPFS): > +@example > +ffplay ipns://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T > +@end example > + > +You can also change the gateway to be used: > + > +@table @option > + > +@item gateway > +Defines the gateway to use. When nothing is provided the protocol will first try > +your local gateway. If that fails dweb.link will be used. > + > +@end table > > @c man end PROTOCOLS > diff --git a/libavformat/Makefile b/libavformat/Makefile > index 3dc6a479cc..983a77f4f2 100644 > --- a/libavformat/Makefile > +++ b/libavformat/Makefile > @@ -656,6 +656,7 @@ OBJS-$(CONFIG_SRTP_PROTOCOL) += srtpproto.o srtp.o > OBJS-$(CONFIG_SUBFILE_PROTOCOL) += subfile.o > OBJS-$(CONFIG_TEE_PROTOCOL) += teeproto.o tee_common.o > OBJS-$(CONFIG_TCP_PROTOCOL) += tcp.o > +OBJS-$(CONFIG_IPFS_PROTOCOL) += ipfs.o > TLS-OBJS-$(CONFIG_GNUTLS) += tls_gnutls.o > TLS-OBJS-$(CONFIG_LIBTLS) += tls_libtls.o > TLS-OBJS-$(CONFIG_MBEDTLS) += tls_mbedtls.o > diff --git a/libavformat/ipfs.c b/libavformat/ipfs.c > new file mode 100644 > index 0000000000..4cc65750ed > --- /dev/null > +++ b/libavformat/ipfs.c > @@ -0,0 +1,202 @@ > +/* > + * IPFS protocol. > + * Copyright (c) 2021 Mark Gaiser > + * > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA > + */ > + > +#include "libavutil/avassert.h" > +#include "libavutil/avstring.h" > +#include "libavutil/internal.h" > +#include "libavutil/opt.h" > +#include "libavutil/tree.h" > +#include "avformat.h" > +#include > +#if HAVE_IO_H > +#include > +#endif > +#if HAVE_UNISTD_H > +#include > +#endif > +#include > +#include > +#include "os_support.h" > +#include "url.h" > + > +typedef struct Context { > + AVClass *class; > + URLContext *inner; > + char *fulluri; > + char *gateway; > +} Context; A more descriptive name would be nice. > + > +static int ipfs_open(URLContext *h, const char *uri, int flags, AVDictionary **options) > +{ > + const char *gatewaysuffix; > + int ret = 0; > + Context *c = h->priv_data; > + > + if (!av_strstart(uri, "ipfs://", &gatewaysuffix) && > + !av_strstart(uri, "ipfs:", &gatewaysuffix)) { > + av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); > + ret = AVERROR(EINVAL); > + goto err; Just return ret. No need for this goto. > + } > + > + char* ipfs_gateway = "https://ipfs.io/ipfs/"; const char* > + > + c->fulluri = malloc(strlen(ipfs_gateway)+strlen(gatewaysuffix) + 1); av_malloc() Also, check the return value for allocation failure. > + > + strcpy(c->fulluri, ipfs_gateway); > + strcat(c->fulluri, gatewaysuffix); > + > + if ((ret = ffurl_open_whitelist(&c->inner, c->fulluri, flags, Is fulluri going to be used after this call? If not, then it should be local to this function as there's no need to have it in h->priv_data (And for that matter, you're not freeing fulluri anywhere). > + &h->interrupt_callback, options, > + h->protocol_whitelist, h->protocol_blacklist, h)) < 0) { You need to define a whitelist including https in both URLProtocol below. > + av_log(h, AV_LOG_ERROR, "Unable to open resource: %s\n", c->fulluri); > + goto err; > + } > + > +err: > + return ret; > +} > + > +static int ipfs_read(URLContext *h, unsigned char *buf, int size) > +{ > + Context *c = h->priv_data; > + int ret; > + > + ret = ffurl_read(c->inner, buf, size); > + > + return ret; > +} > + > +static int64_t ipfs_seek(URLContext *h, int64_t pos, int whence) > +{ > + Context *c = h->priv_data; > + int64_t ret; > + > + ret = ffurl_seek(c->inner, pos, whence); > + > + return ret; > +} > + > +static int ipfs_close(URLContext *h) > +{ > + Context *c = h->priv_data; > + int ret; > + > + ret = ffurl_closep(&c->inner); > + > + return ret; > +} > + > +static int ipns_open(URLContext *h, const char *uri, int flags, AVDictionary **options) > +{ > + const char *gatewaysuffix; > + int ret = 0; > + Context *c = h->priv_data; > + > + if (!av_strstart(uri, "ipns://", &gatewaysuffix) && > + !av_strstart(uri, "ipns:", &gatewaysuffix)) { > + av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); > + ret = AVERROR(EINVAL); > + goto err; > + } > + > + char* ipfs_gateway = "https://ipfs.io/ipns/"; > + > + c->fulluri = malloc(strlen(ipfs_gateway)+strlen(gatewaysuffix) + 1); > + > + strcpy(c->fulluri, ipfs_gateway); > + strcat(c->fulluri, gatewaysuffix); > + > + if ((ret = ffurl_open_whitelist(&c->inner, c->fulluri, flags, > + &h->interrupt_callback, options, > + h->protocol_whitelist, h->protocol_blacklist, h)) < 0) { > + av_log(h, AV_LOG_ERROR, "Unable to open resource: %s\n", c->fulluri); > + goto err; > + } > + > +err: > + return ret; Same comments as above apply here. > +} > + > +static int ipns_read(URLContext *h, unsigned char *buf, int size) > +{ > + Context *c = h->priv_data; > + int ret; > + > + ret = ffurl_read(c->inner, buf, size); > + > + return ret; > +} > + > +static int64_t ipns_seek(URLContext *h, int64_t pos, int whence) > +{ > + Context *c = h->priv_data; > + int64_t ret; > + > + ret = ffurl_seek(c->inner, pos, whence); > + > + return ret; > +} > + > +static int ipns_close(URLContext *h) > +{ > + Context *c = h->priv_data; > + int ret; > + > + ret = ffurl_closep(&c->inner); > + > + return ret; > +} > + > +#define OFFSET(x) offsetof(Context, x) > +#define D AV_OPT_FLAG_DECODING_PARAM > + > +static const AVOption options[] = { > + {"gateway", "The gateway to ask for IPFS data.", OFFSET(gateway), AV_OPT_TYPE_BINARY, .flags = D }, > + {NULL}, > +}; > + > +static const AVClass ipfs_context_class = { > + .class_name = "IPFS", > + .item_name = av_default_item_name, > + .option = options, > + .version = LIBAVUTIL_VERSION_INT, > +}; > + > +const URLProtocol ff_ipfs_protocol = { > + .name = "ipfs", > + .url_open2 = ipfs_open, > + .url_read = ipfs_read, > + .url_seek = ipfs_seek, > + .url_close = ipfs_close, > + .priv_data_size = sizeof(Context), > + .priv_data_class = &ipfs_context_class, > +}; > + > +const URLProtocol ff_infs_protocol = { > + .name = "ipns", > + .url_open2 = ipfs_open, > + .url_read = ipfs_read, > + .url_seek = ipfs_seek, > + .url_close = ipfs_close, > + .priv_data_size = sizeof(Context), > + .priv_data_class = &ipfs_context_class, > +}; > diff --git a/libavformat/protocols.c b/libavformat/protocols.c > index 948fae411f..675b684bd3 100644 > --- a/libavformat/protocols.c > +++ b/libavformat/protocols.c > @@ -73,6 +73,8 @@ extern const URLProtocol ff_libsrt_protocol; > extern const URLProtocol ff_libssh_protocol; > extern const URLProtocol ff_libsmbclient_protocol; > extern const URLProtocol ff_libzmq_protocol; > +extern const URLProtocol ff_ipfs_protocol; > +extern const URLProtocol ff_ipns_protocol; > > #include "libavformat/protocol_list.c" > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".