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

feat: Ipnisync #1731

Merged
merged 8 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ docsgen-openrpc-boost: docsgen-openrpc-bin

## DOCKER IMAGES
docker_user?=filecoin
lotus_version?=lotus@v1.23.4-rc1
lotus_version?=v1.23.4-rc1
ffi_from_source?=0
build_lotus?=0
build_boost?=1
Expand Down
31 changes: 31 additions & 0 deletions gql/resolver_ipni.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"

"github.com/ipfs/go-cid"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipni/go-libipni/ingest/schema"
"github.com/ipni/go-libipni/metadata"
"github.com/multiformats/go-multicodec"
Expand Down Expand Up @@ -198,3 +199,33 @@ func resolveAd(ad *schema.Advertisement) *adResolver {
}
return res
}

func (r *resolver) IpniDistanceFromLatestAd(ctx context.Context, args struct {
LatestAdcid string
Adcid string
}) (int32, error) {
count := int32(0)
if args.Adcid == args.LatestAdcid {
return count, nil
}
LatestAd, err := cid.Parse(args.LatestAdcid)
LexLuthr marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return count, fmt.Errorf("parsing ad cid %s: %w", args.LatestAdcid, err)
}

ad, err := r.idxProv.GetAdv(ctx, LatestAd)
if err != nil {
return count, err
}

for ad.PreviousID.String() != args.Adcid {
prevCid := ad.PreviousID.(cidlink.Link).Cid
ad, err = r.idxProv.GetAdv(ctx, prevCid)
if err != nil {
return count, err
}
count++
}

return count, nil
}
3 changes: 3 additions & 0 deletions gql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ type RootQuery {

"""Get the payload CIDs and corresponding multihashes for a particular piece CID"""
piecePayloadCids(pieceCid: String!): [PiecePayload]!

"""Get the latest IPNI advertisemen"""
ipniDistanceFromLatestAd(LatestAdcid: String!, Adcid: String!): Int!
}

type RootMutation {
Expand Down
2 changes: 1 addition & 1 deletion node/config/doc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 24 additions & 4 deletions react/src/Ipni.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IpniAdQuery,
IpniProviderInfoQuery,
IpniLatestAdQuery,
RetrievalLogsCountQuery, RetrievalLogsListQuery,
RetrievalLogsCountQuery, RetrievalLogsListQuery, IpniDistanceFromLatestAdQuery,
} from "./gql";
import moment from "moment";
import React, {useEffect, useState} from "react";
Expand Down Expand Up @@ -34,7 +34,6 @@ export function IpniPage(props) {
return <PageContainer pageType="ipni" title="Network Indexer">
<div className="ipni">
<ProviderInfo />
<RetrievalLogsContent />
</div>
</PageContainer>
}
Expand Down Expand Up @@ -71,12 +70,31 @@ function ProviderIpniInfo({peerId}) {
}).then((data) => {
setResp({ loading: false, data })
}).catch((err) => setResp({ loading: false, error: err }))
}, [])
}, [idxHost, peerId])

if (error) return <div>Error: {"Fetching provider info from "+idxHost+": "+error.message}</div>
if (loading) return <div>Loading...</div>
if (!data) return null

return <>
<ProviderIpniInfoRender data={data} idxHost={idxHost} lad={head.data.ipniLatestAdvertisement} />
</>
}

function ProviderIpniInfoRender(props){
const data = props.data
const idxHost = props.idxHost
const lad = props.lad
let ADCID = data.LastAdvertisement['/']
LexLuthr marked this conversation as resolved.
Show resolved Hide resolved
if (process.env.NODE_ENV === 'development') {
ADCID = 'baguqeera4d4mgsbukpnlwu4bxuwir2pbchhdar4gmz3ti75cxuwhiviyowua'
}
const distance = useQuery(IpniDistanceFromLatestAdQuery, {
variables: {
latestAdcid: lad,
adcid: ADCID
}
})
return <div className="ipni-prov-info">
<h3>Provider Indexer Info</h3>
<div className="subtitle">
Expand All @@ -98,12 +116,14 @@ function ProviderIpniInfo({peerId}) {
{data.LastAdvertisement['/']}
&nbsp;
<span className="aux">({moment(data.LastAdvertisementTime).fromNow()} ago)</span>
&nbsp;
{distance.data ? <span className="aux">({distance.data.ipniDistanceFromLatestAd} behind)</span>: ''}
</td>
</tr>
<tr>
<th>Latest Advertisement on Boost</th>
<td>
{head.data ? <Link to={'/ipni/ad/'+head.data.ipniLatestAdvertisement}>{head.data.ipniLatestAdvertisement}</Link>: ''}
{lad ? <Link to={'/ipni/ad/'+lad}>{lad}</Link>: ''}
</td>
</tr>
<tr>
Expand Down
7 changes: 7 additions & 0 deletions react/src/gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,12 @@ const PiecePayloadCidsQuery = gql`
}
`;

const IpniDistanceFromLatestAdQuery = gql`
query AppIpniDistanceFromLatestAdQuery($latestAdcid: String!, $adcid: String!) {
ipniDistanceFromLatestAd(LatestAdcid: $latestAdcid, Adcid: $adcid)
}
`;

export {
gqlClient,
EpochQuery,
Expand All @@ -817,6 +823,7 @@ export {
IpniAdEntriesQuery,
IpniAdEntriesCountQuery,
IpniLatestAdQuery,
IpniDistanceFromLatestAdQuery,
PiecesWithPayloadCidQuery,
PieceBuildIndexMutation,
PieceStatusQuery,
Expand Down