示例#1
0
 public async Task Run([PerperStreamTrigger] PerperStreamContext context,
                       [Perper("chains")] Dictionary <Guid, Chain> chains,
                       [Perper("gossips")] IPerperStream gossips,
                       [Perper("queries")] IPerperStream queries,
                       [Perper("hashRegistry")] IPerperStream hashRegistry,
                       [Perper("slotGossips")] IAsyncEnumerable <SlotClaim> slotGossips,
                       [Perper("salts")] IAsyncEnumerable <(Guid, int, byte[])> salts,
示例#2
0
        public async Task <IPerperStream> StreamActionAsync(IPerperStream declaration, object parameters)
        {
            var streamObject = ((PerperFabricStream)declaration);

            await StreamActionAsync(streamObject.StreamName, streamObject.DeclaredDelegate, parameters);

            return(declaration);
        }
示例#3
0
 public async Task Run([PerperStreamTrigger] PerperStreamContext context,
                       [Perper("input")] IPerperStream input,
                       [Perper("output")] IAsyncCollector <IPerperStream> output,
                       ILogger logger,
                       CancellationToken cancellationToken)
 {
     await output.AddAsync(input, cancellationToken);
 }
示例#4
0
        public static async Task RunAsync([PerperStreamTrigger] PerperStreamContext context,
                                          [Perper("processor")] IPerperStream processor,
                                          ILogger logger, CancellationToken cancellationToken)
        {
            logger.LogInformation($"Starting pass-through consumer");
            await using var consumer =
                            await context.StreamActionAsync("NamedConsumer", typeof(Consumer), new { processor = processor.Subscribe() });

            await context.BindOutput(cancellationToken);
        }
示例#5
0
        public async Task <IPerperStream> StartAsync(
            [PerperModuleTrigger] PerperModuleContext context,
            [Perper("input")] IPerperStream input,
            CancellationToken cancellationToken,
            ILogger logger)
        {
            logger.LogInformation("Started AgentPong module...");

            var runtimeStream = await context.StreamFunctionAsync(typeof(AgentPongRuntimeStream), new { input = input.Subscribe() });

            return(runtimeStream);
        }
示例#6
0
        public IQueryable <T> Query <T>(IPerperStream stream)
        {
            var perperFabricStream = stream as PerperFabricStream;

            if (perperFabricStream !.FilterField != null)
            {
                throw new NotImplementedException("Querying filtered streams is not supported in this version of Perper.");
            }

            var streamName = perperFabricStream !.StreamName;
            var data       = _context.GetData(streamName);

            return(data.QueryStreamItemsAsync <T>());
        }
示例#7
0
        public async Task Run([PerperStreamTrigger] PerperStreamContext context,
                              [Perper("chains")] Dictionary <Guid, Chain> chains,
                              [Perper("ibc")] IAsyncEnumerable <Message <Hash> > ibc,
                              [Perper("gossips")] IAsyncEnumerable <Gossip <Hash> > gossips,
                              [Perper("hashRegistry")] IPerperStream hashRegistry,
                              [Perper("output")] IAsyncCollector <object> output,
                              CancellationToken cancellationToken)
        {
            _hashRegistry = context.Query <HashRegistryEntry>(hashRegistry);
            _output       = output;

            foreach (var(chainId, chain) in chains)
            {
                var executor = new Executor(chainId,
                                            async(worker, input) => await context.CallWorkerAsync <(byte[]?, (string, object[])[], Dictionary <Guid, string[]>, Dictionary <Guid, string>)>(worker, new { input }, default));
示例#8
0
        public async Task Run([PerperStreamTrigger] PerperStreamContext context,
                              [Perper("node")] Node node,
                              [Perper("chainData")] Chain chainData,
                              [Perper("consensus")] IAsyncEnumerable <Message <Hash> > consensus,
                              [Perper("filter")] IAsyncEnumerable <Hash> filter,
                              [Perper("queries")] IAsyncEnumerable <Query <Hash> > queries,
                              [Perper("hashRegistry")] IPerperStream hashRegistry,
                              [Perper("output")] IAsyncCollector <Message <Hash> > output,
                              CancellationToken cancellationToken)
        {
            _output       = output;
            _node         = node;
            _hashRegistry = context.Query <HashRegistryEntry>(hashRegistry);

            var executor = new Executor(_node !.ChainId,
                                        async(worker, input) => await context.CallWorkerAsync <(byte[]?, (string, object[])[], Dictionary <Guid, string[]>, Dictionary <Guid, string>)>(worker, new { input }, default));
示例#9
0
 public async Task Run([PerperStreamTrigger] PerperStreamContext context,
                       [Perper("chains")] Dictionary <Guid, Chain> chains,
                       [Perper("filter")] IAsyncEnumerable <Hash> filter,
                       [Perper("hashRegistry")] IPerperStream hashRegistryStream,
                       [Perper("output")] IAsyncCollector <(Guid, int, byte[])> output,
示例#10
0
        public async Task Run([PerperStreamTrigger] PerperStreamContext context,
                              [Perper("slotGossips")] IPerperStream slotGossips,
                              [Perper("chains")] IDictionary <Guid, Chain> chains,
                              [Perper("output")] IAsyncCollector <int> output,
                              CancellationToken cancellationToken)
        {
            await using var peering = context.DeclareStream("Peering", typeof(PeeringStream));
            var gossips = peering;
            var queries = peering;
            var reports = peering;
            var hashes  = peering;

            await using var salts = context.DeclareStream("Salts", typeof(SaltsStream));

            await using var hashRegistry = await context.StreamFunctionAsync("HashRegistry", typeof(HashRegistryStream), new
            {
                filter = typeof(Block),
                input  = hashes.Subscribe()
            }, typeof(HashRegistryEntry));

            await context.StreamActionAsync("DummyStream", new
            {
                hashRegistry = hashRegistry.Subscribe() // HACK: Ensure hash registry is started up before anything else
            });

            await using var chain = await context.StreamFunctionAsync("Chain", typeof(ChainStream), new
            {
                chains,
                gossips,
                queries,
                hashRegistry,
                salts       = salts.Subscribe(),
                slotGossips = slotGossips.Subscribe()
            });

            // HACK: Create an empty stream for the global IBC
            await using var validator = await context.StreamFunctionAsync("DummyStream", new
            {
                peering      = peering.Subscribe(),     // HACK: Ensure peering is started before it starts receiving streams
                hashRegistry = hashRegistry.Subscribe() // HACK: Ensure hash registry is started up
            });

            await using var ibc = await context.StreamFunctionAsync("IBC-global", typeof(IBCStream), new
            {
                chain     = chain.Subscribe(),
                validator = validator.Subscribe(),
                gossips   = gossips.Subscribe(),
                nodes     = new Dictionary <Guid, Node?[]>(),
                node      = default(Node?)
            });

            await using var filter = await context.StreamFunctionAsync("Filter-global", typeof(FilterStream), new
            {
                ibc     = ibc.Subscribe(),
                gossips = gossips.Subscribe(),
                hashRegistry,
                chains
            });

            await context.StreamFunctionAsync(salts, new
            {
                chains,
                hashRegistry = hashRegistry,
                filter       = filter.Subscribe()
            });

            await context.StreamFunctionAsync(peering, new
            {
                factory = chain.Subscribe(),
                initial = new List <IPerperStream>()
                {
                    filter
                },
            });

            await using var reportsStream = await context.StreamActionAsync(typeof(ReportsStream), new
            {
                hashRegistry = hashRegistry,
                chain        = chain.Subscribe(),
                nodes        = new Dictionary <Guid, Node?[]>(),
                filter       = filter.Subscribe(),
                reports      = reports.Subscribe()
            });

            await context.BindOutput(cancellationToken);
        }
示例#11
0
 public Task BindOutput(IPerperStream stream, CancellationToken cancellationToken)
 {
     return(BindOutput(new [] { stream }, cancellationToken));
 }
示例#12
0
        public async Task <IPerperStream> StreamActionAsync(IPerperStream declaration, object parameters)
        {
            var data = _context.GetData(StreamName);

            return(await data.StreamActionAsync(declaration, parameters));
        }