Skip to content
This repository was archived by the owner on Jan 25, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 22 additions & 9 deletions realm/lib/passport.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
|= [our=ship =type:common data=columns:db]
(create-req our type data [our *@da])
::
++ create-many
|= [our=ship args=(list [req-id input-row:db])]
[%pass /dbpoke %agent [our %bedrock] %poke %db-action !>([%create-many args])]
::
++ edit-req
|= [our=ship =type:common =id:common data=columns:db =req-id]
^- card
Expand Down Expand Up @@ -258,27 +262,36 @@
|= [contacts=(list [t=@da =contact:common]) state=state-0 =bowl:gall]
^- (quip card state-0)
?< =(src.bowl our.bowl) :: assert we aren't receiving from ourself
=/ log1 (maybe-log hide-logs.state "%receive-contacts: {<contacts>}")
=/ log1 (maybe-log hide-logs.state "%receive-contacts: {<(lent contacts)>} contacts {<now.bowl>}")

:: loop through the contacts they sent us
=/ old=(list [id:common @da contact:common]) (our-contacts:scries bowl)
=/ cards=(list card) ~
=/ create-args=(list [req-id input-row:db]) ~
|-
?: =(0 (lent contacts))
[cards state]
=/ log2 (maybe-log hide-logs.state "%receive-contacts finished at {<now.bowl>} ")
?: =(0 (lent create-args))
[cards state]
~& > "lent of create-args {<(lent create-args)>}"
~& > "lent of cards {<(lent cards)>}"
:_ state
:- (create-many our.bowl create-args)
cards
=/ con=contact:common (cleanup-contact contact:(snag 0 contacts))
?: =(our.bowl ship.con) :: don't create a contact record for ourselves
$(contacts +.contacts)
=/ index=(unit @) (find-contact con old)
=/ new-card=(unit card)
?~ index
(some (create our.bowl contact-type:common [%contact con]))
=/ old-con=[=id:common t=@da =contact:common] (snag u.index old)
?: (gth t.old-con t:(snag 0 contacts)) ~ :: if our old record is newer than the one we are getting, ignore it
(some (edit our.bowl contact-type:common id.old-con [%contact con]))
?~ index
%= $
contacts +.contacts
create-args [[[our.bowl *@da] [/private contact-type:common [%contact con] ~]] create-args]
==
=/ old-con=[=id:common t=@da =contact:common] (snag u.index old)
?: (gth t.old-con t:(snag 0 contacts)) $(contacts +.contacts) :: if our old record is newer than the one we are getting, ignore it
%= $
contacts +.contacts
cards ?~(new-card cards [u.new-card cards])
cards [(edit our.bowl contact-type:common id.old-con [%contact con]) cards]
==
::
++ request-contacts
Expand Down
48 changes: 48 additions & 0 deletions realm/ted/make-fake-contacts.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
:: -realm!make-fake-contacts 10
/- spider, common
/+ *strandio

|^
=, strand=strand:spider
^- thread:spider
|= arg=vase
=/ m (strand ,vase)
^- form:m
=/ axn=(unit @ud) !<((unit @ud) arg)
?~ axn (strand-fail %no-arg ~)
;< our=@p bind:m get-our
;< now=@da bind:m get-time
=/ i=@ud 1
|-
?: =(u.axn i)
(pure:m !>(`@p`i))
=/ cont=contact:common
[
`@p`i
[~ [%nft nft='https://steamavatar.io/img/1477787732RP7QJ.jpg']]
[~ '#B17BD7']
[~ 'Just another test moon']
[~ 'Paul']
]
;< ~ bind:m (poke [our %bedrock] db-action+!>([%create [our (add now i)] /private contact-type:common [%contact cont] ~]))
$(i +(i))
::
++ take-fact-or-kick
|= =wire
=/ m (strand ,(unit cage))
^- form:m
|= tin=strand-input:strand
?+ in.tin `[%skip ~]
~ `[%wait ~]
::
[~ %agent * %fact *]
?. =(watch+wire wire.u.in.tin)
`[%skip ~]
`[%done (some cage.sign.u.in.tin)]
::
[~ %agent * %kick *]
?. =(watch+wire wire.u.in.tin)
`[%skip ~]
`[%done ~]
==
--
21 changes: 21 additions & 0 deletions realm/ted/send-all-contacts.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
:: -realm!send-all-contacts ~bus
/- spider
/+ *strandio, passport

|^
=, strand=strand:spider
^- thread:spider
|= arg=vase
=/ m (strand ,vase)
^- form:m
=/ axn=(unit @p) !<((unit @p) arg)
?~ axn (strand-fail %no-arg ~)
;< our=@p bind:m get-our
;< now=@da bind:m get-time
=/ bol=bowl:gall *bowl:gall
=. our.bol our
=. now.bol now
~& >>> "starting send-all-contacts {<now>}"
;< ~ bind:m (poke [u.axn %passport] passport-action+!>([%receive-contacts (current-contacts:passport bol)]))
(pure:m !>('sent'))
--