From 7084d8951d558838b3babee469144512ad4038ca Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 14 Apr 2021 20:24:36 -0700 Subject: [PATCH 01/42] Revert "Merge pull request #4769 from urbit/revert-4766-jb/cttp-crash-fix" This reverts commit 6d17d4c845ba8d94a642066361981a18f877e3c7, reversing changes made to 8f330c2ddb53c26afaae1b91778487c0a01961f0. --- pkg/urbit/vere/io/cttp.c | 51 +++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/pkg/urbit/vere/io/cttp.c b/pkg/urbit/vere/io/cttp.c index 0d0fbb1ba..2b091433d 100644 --- a/pkg/urbit/vere/io/cttp.c +++ b/pkg/urbit/vere/io/cttp.c @@ -559,13 +559,18 @@ _cttp_creq_new(u3_cttp* ctp_u, c3_l num_l, u3_noun hes) return 0; } - // Parse the url out of the new style url passed to us. + // parse the url out of the new style url passed to us. + // u3_noun unit_pul = u3do("de-purl:html", u3k(url)); - if (c3n == u3r_du(unit_pul)) { - u3l_log("cttp: url parsing failed\n"); + + if ( c3n == u3r_du(unit_pul) ) { + c3_c* url_c = u3r_string(url); + u3l_log("cttp: unable to parse url:\n %s\n", url_c); + c3_free(url_c); u3z(hes); return 0; } + u3_noun pul = u3t(unit_pul); u3_noun hat = u3h(pul); // +hart @@ -817,7 +822,7 @@ _cttp_creq_on_head(h2o_http1client_t* cli_u, const c3_c* err_c, c3_i ver_i, */ static h2o_http1client_head_cb _cttp_creq_on_connect(h2o_http1client_t* cli_u, const c3_c* err_c, - h2o_iovec_t** vec_p, size_t* vec_t, c3_i* hed_i) + h2o_iovec_t** vec_u, size_t* vec_i, c3_i* hed_i) { u3_creq* ceq_u = (u3_creq *)cli_u->data; @@ -826,11 +831,16 @@ _cttp_creq_on_connect(h2o_http1client_t* cli_u, const c3_c* err_c, return 0; } + // serialize request (populate rub_u) + // + _cttp_creq_fire(ceq_u); + { c3_w len_w; ceq_u->vec_u = _cttp_bods_to_vec(ceq_u->rub_u, &len_w); - *vec_t = len_w; - *vec_p = ceq_u->vec_u; + + *vec_i = len_w; + *vec_u = ceq_u->vec_u; *hed_i = (0 == strcmp(ceq_u->met_c, "HEAD")); } @@ -842,24 +852,28 @@ _cttp_creq_on_connect(h2o_http1client_t* cli_u, const c3_c* err_c, static void _cttp_creq_connect(u3_creq* ceq_u) { - c3_assert(u3_csat_ripe == ceq_u->sat_e); - c3_assert(ceq_u->ipf_c); + c3_assert( u3_csat_ripe == ceq_u->sat_e ); + c3_assert( ceq_u->ipf_c ); - h2o_iovec_t ipf_u = h2o_iovec_init(ceq_u->ipf_c, strlen(ceq_u->ipf_c)); - c3_s por_s = ceq_u->por_s ? ceq_u->por_s : - ( c3y == ceq_u->sec ) ? 443 : 80; - - // connect by IP - h2o_http1client_connect(&ceq_u->cli_u, ceq_u, &ceq_u->ctp_u->ctx_u, ipf_u, - por_s, c3y == ceq_u->sec, _cttp_creq_on_connect); - - // set hostname for TLS handshake + // set hostname for TLS handshake + // if ( ceq_u->hot_c && c3y == ceq_u->sec ) { c3_free(ceq_u->cli_u->ssl.server_name); ceq_u->cli_u->ssl.server_name = strdup(ceq_u->hot_c); } - _cttp_creq_fire(ceq_u); + // connect by IP + // + { + h2o_iovec_t ipf_u = h2o_iovec_init(ceq_u->ipf_c, strlen(ceq_u->ipf_c)); + c3_t tls_t = ( c3y == ceq_u->sec ); + c3_s por_s = ( ceq_u->por_s ) + ? ceq_u->por_s + : ( tls_t ) ? 443 : 80; + + h2o_http1client_connect(&ceq_u->cli_u, ceq_u, &ceq_u->ctp_u->ctx_u, + ipf_u, por_s, tls_t, _cttp_creq_on_connect); + } } /* _cttp_creq_resolve_cb(): cb upon IP address resolution @@ -981,7 +995,6 @@ _cttp_ef_http_client(u3_cttp* ctp_u, u3_noun tag, u3_noun dat) ret_o = c3y; } else { - u3l_log("cttp: strange request (unparsable url)\n"); ret_o = c3n; } } From e6857d5797e4ddac0c21c1fc77727fa005faf885 Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Tue, 20 Apr 2021 15:32:26 +1000 Subject: [PATCH 02/42] king: do not commit files starting with a dot --- pkg/hs/urbit-king/lib/Urbit/Vere/Clay.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/hs/urbit-king/lib/Urbit/Vere/Clay.hs b/pkg/hs/urbit-king/lib/Urbit/Vere/Clay.hs index c29fced79..99b3f2643 100644 --- a/pkg/hs/urbit-king/lib/Urbit/Vere/Clay.hs +++ b/pkg/hs/urbit-king/lib/Urbit/Vere/Clay.hs @@ -42,7 +42,7 @@ validClaySyncPath fp = hasPeriod && notTildeFile && notDotHash && notDoubleHash fileName = takeFileName fp hasPeriod = elem '.' fileName notTildeFile = not $ "~" `isSuffixOf` fileName - notDotHash = not $ ".#" `isPrefixOf` fileName + notDotHash = not $ "." `isPrefixOf` fileName notDoubleHash = not $ ("#" `isPrefixOf` fileName) && ("#" `isSuffixOf` fileName) From 2389727f8f9bf29d42caa340562a350875095a95 Mon Sep 17 00:00:00 2001 From: ~locpyl-tidnyd Date: Sat, 27 Mar 2021 20:12:27 +0000 Subject: [PATCH 03/42] u3: centralize use of u3_Signal --- pkg/urbit/noun/manage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/urbit/noun/manage.c b/pkg/urbit/noun/manage.c index 23ad01e53..a63564bf7 100644 --- a/pkg/urbit/noun/manage.c +++ b/pkg/urbit/noun/manage.c @@ -127,7 +127,7 @@ static void _cm_overflow(void *arg1, void *arg2, void *arg3) (void)(arg1); (void)(arg2); (void)(arg3); - siglongjmp(u3_Signal, c3__over); + u3m_signal(c3__over); } /* _cm_signal_handle(): handle a signal in general. @@ -139,7 +139,7 @@ _cm_signal_handle(c3_l sig_l) sigsegv_leave_handler(_cm_overflow, NULL, NULL, NULL); } else { - siglongjmp(u3_Signal, sig_l); + u3m_signal(sig_l); } } From 1a257b525c4d00af6eecddbb9bdd5a6771c220c0 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 20 Apr 2021 11:56:37 -0700 Subject: [PATCH 04/42] u3: allow bail:meme through (a la bail:fail) --- pkg/urbit/noun/manage.c | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/urbit/noun/manage.c b/pkg/urbit/noun/manage.c index a63564bf7..baddb6446 100644 --- a/pkg/urbit/noun/manage.c +++ b/pkg/urbit/noun/manage.c @@ -688,7 +688,6 @@ u3m_bail(u3_noun how) // switch ( how ) { case c3__foul: - case c3__meme: case c3__oops: { fprintf(stderr, "bailing out\r\n"); abort(); From e32a9b2c75df23317091668f9e4d3fd8fd80c576 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 20 Apr 2021 11:58:38 -0700 Subject: [PATCH 05/42] u3: abort all home-road bails --- pkg/urbit/noun/manage.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/urbit/noun/manage.c b/pkg/urbit/noun/manage.c index baddb6446..d246ab84a 100644 --- a/pkg/urbit/noun/manage.c +++ b/pkg/urbit/noun/manage.c @@ -661,7 +661,10 @@ u3m_dump(void) c3_i u3m_bail(u3_noun how) { - if ( (c3__exit == how) && (u3R == &u3H->rod_u) ) { + if ( &(u3H->rod_u) == u3R ) { + // XX set exit code + // + fprintf(stderr, "home: bailing out\r\n"); abort(); } @@ -689,6 +692,8 @@ u3m_bail(u3_noun how) switch ( how ) { case c3__foul: case c3__oops: { + // XX set exit code + // fprintf(stderr, "bailing out\r\n"); abort(); } @@ -699,6 +704,9 @@ u3m_bail(u3_noun how) // choice but to use the signal process; and we require the flat // form of how. // + // XX JB: these seem unrecoverable, at least wrt memory management, + // so they've been disabled above for now + // c3_assert(_(u3a_is_cat(how))); u3m_signal(how); } From d357593ef1500a8b12c5217d52709075dabf2ccc Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Wed, 21 Apr 2021 16:40:22 +1000 Subject: [PATCH 06/42] king: address ~pilfer-pandex review --- pkg/hs/urbit-king/lib/Urbit/Vere/Clay.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/hs/urbit-king/lib/Urbit/Vere/Clay.hs b/pkg/hs/urbit-king/lib/Urbit/Vere/Clay.hs index 99b3f2643..e76fdba2c 100644 --- a/pkg/hs/urbit-king/lib/Urbit/Vere/Clay.hs +++ b/pkg/hs/urbit-king/lib/Urbit/Vere/Clay.hs @@ -37,12 +37,12 @@ textPlain = Path [(MkKnot "text"), (MkKnot "plain")] -- | Filter for dotfiles, tempfiles and backup files. validClaySyncPath :: FilePath -> Bool -validClaySyncPath fp = hasPeriod && notTildeFile && notDotHash && notDoubleHash +validClaySyncPath fp = hasPeriod && notTildeFile && notDotFile && notDoubleHash where fileName = takeFileName fp hasPeriod = elem '.' fileName notTildeFile = not $ "~" `isSuffixOf` fileName - notDotHash = not $ "." `isPrefixOf` fileName + notDotFile = not $ "." `isPrefixOf` fileName notDoubleHash = not $ ("#" `isPrefixOf` fileName) && ("#" `isSuffixOf` fileName) From 156d0d380d7bd18f8eeee9c418b1287eb296b1ed Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Wed, 21 Apr 2021 11:44:00 -0400 Subject: [PATCH 07/42] ColorInput: remove "#" from input value Fixes urbit/landscape#803 --- pkg/interface/src/views/components/ColorInput.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/interface/src/views/components/ColorInput.tsx b/pkg/interface/src/views/components/ColorInput.tsx index 0a4036e7c..adbe0532f 100644 --- a/pkg/interface/src/views/components/ColorInput.tsx +++ b/pkg/interface/src/views/components/ColorInput.tsx @@ -73,7 +73,7 @@ export function ColorInput(props: ColorInputProps) { height='100%' alignSelf='stretch' onChange={onChange} - value={`#${padded}`} + value={padded} disabled={disabled || false} type='color' opacity={0} From a78029544846170f96082dad18007e7b424f92f4 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 20 Apr 2021 11:59:04 -0700 Subject: [PATCH 08/42] u3: remove unwanted assertions in emergency printf --- pkg/urbit/noun/manage.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/pkg/urbit/noun/manage.c b/pkg/urbit/noun/manage.c index d246ab84a..4833228ff 100644 --- a/pkg/urbit/noun/manage.c +++ b/pkg/urbit/noun/manage.c @@ -98,28 +98,22 @@ _cm_punt(u3_noun tax) } #endif -static void _write(int fd, const void *buf, size_t count) -{ - if (count != write(fd, buf, count)){ - u3l_log("write failed\r\n"); - c3_assert(0); - } -} - - /* _cm_emergency(): write emergency text to stderr, never failing. */ static void _cm_emergency(c3_c* cap_c, c3_l sig_l) { - _write(2, "\r\n", 2); - _write(2, cap_c, strlen(cap_c)); + c3_i ret_i; + + ret_i = write(2, "\r\n", 2); + ret_i = write(2, cap_c, strlen(cap_c)); if ( sig_l ) { - _write(2, ": ", 2); - _write(2, &sig_l, 4); + ret_i = write(2, ": ", 2); + ret_i = write(2, &sig_l, 4); } - _write(2, "\r\n", 2); + + ret_i = write(2, "\r\n", 2); } static void _cm_overflow(void *arg1, void *arg2, void *arg3) From 8124f63215f8167a92c50ce76449e08229a777a2 Mon Sep 17 00:00:00 2001 From: James Acklin Date: Wed, 21 Apr 2021 14:58:16 -0400 Subject: [PATCH 09/42] chat: flush borders + round corners for images --- pkg/interface/src/views/components/RemoteContent.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/interface/src/views/components/RemoteContent.tsx b/pkg/interface/src/views/components/RemoteContent.tsx index 648ab72b1..7825b3598 100644 --- a/pkg/interface/src/views/components/RemoteContent.tsx +++ b/pkg/interface/src/views/components/RemoteContent.tsx @@ -145,7 +145,7 @@ return; )} { e.stopPropagation(); }} href={this.props.url} whiteSpace="nowrap" @@ -205,6 +205,7 @@ return; height="100%" width="100%" objectFit="contain" + borderRadius={2} {...imageProps} {...props} /> From 6d9508abfce86eed4186816269447f0c5d62b2bc Mon Sep 17 00:00:00 2001 From: James Acklin Date: Wed, 21 Apr 2021 14:59:16 -0400 Subject: [PATCH 10/42] chat: flush borders + round corners for images --- pkg/interface/src/views/components/RemoteContent.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/interface/src/views/components/RemoteContent.tsx b/pkg/interface/src/views/components/RemoteContent.tsx index 7825b3598..8e0ee5bf6 100644 --- a/pkg/interface/src/views/components/RemoteContent.tsx +++ b/pkg/interface/src/views/components/RemoteContent.tsx @@ -128,7 +128,7 @@ return; }); } - wrapInLink(contents, textOnly = false, unfold = false, unfoldEmbed = null, embedContainer = null) { + wrapInLink(contents, textOnly = false, unfold = false, unfoldEmbed = null, embedContainer = null, flushPadding = false) { const { style } = this.props; return ( @@ -145,7 +145,7 @@ return; )} { e.stopPropagation(); }} href={this.props.url} whiteSpace="nowrap" @@ -208,7 +208,7 @@ return; borderRadius={2} {...imageProps} {...props} - /> + />, false, false, null, null, true ); } else if (isAudio && remoteContentPolicy.audioShown) { return ( @@ -272,7 +272,6 @@ return; display={this.state.unfold ? 'block' : 'none'} className='embed-container' style={style} - flexShrink={0} onLoad={this.onLoad} {...oembedProps} {...props} From 3d40d37e801884d1a7950a630421dcf0a98db5b7 Mon Sep 17 00:00:00 2001 From: James Acklin Date: Wed, 21 Apr 2021 15:00:14 -0400 Subject: [PATCH 11/42] interface: new messages icon partially fixes urbit/landscape#560 --- pkg/interface/src/views/components/StatusBar.js | 2 +- pkg/interface/src/views/components/leap/OmniboxResult.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/interface/src/views/components/StatusBar.js b/pkg/interface/src/views/components/StatusBar.js index f2bc362db..66e12843f 100644 --- a/pkg/interface/src/views/components/StatusBar.js +++ b/pkg/interface/src/views/components/StatusBar.js @@ -134,7 +134,7 @@ const StatusBar = (props) => { mr={2} onClick={() => props.history.push('/~landscape/messages')} > - + Date: Wed, 21 Apr 2021 15:02:57 -0400 Subject: [PATCH 12/42] chat: pointer cursor for attachment + dojo in input --- pkg/interface/src/views/apps/chat/components/ChatInput.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx index 1a170ef45..dab2c1169 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx @@ -189,6 +189,7 @@ class ChatInput extends Component { ) : ( @@ -201,6 +202,7 @@ class ChatInput extends Component { From d585c58b8f46db34899daffba94d57702ed42ab0 Mon Sep 17 00:00:00 2001 From: James Acklin Date: Wed, 21 Apr 2021 15:41:14 -0400 Subject: [PATCH 13/42] chat: click name to copy ~patp in ProfileOverlay --- pkg/interface/src/views/components/ProfileOverlay.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/interface/src/views/components/ProfileOverlay.tsx b/pkg/interface/src/views/components/ProfileOverlay.tsx index 2e9432748..0e9218604 100644 --- a/pkg/interface/src/views/components/ProfileOverlay.tsx +++ b/pkg/interface/src/views/components/ProfileOverlay.tsx @@ -23,6 +23,7 @@ import RichText from './RichText'; import { ProfileStatus } from './ProfileStatus'; import useSettingsState from '~/logic/state/settings'; import {useOutsideClick} from '~/logic/lib/useOutsideClick'; +import {useCopy} from '~/logic/lib/useCopy'; import {useContact} from '~/logic/state/contact'; import {useHistory} from 'react-router-dom'; import {Portal} from './Portal'; @@ -59,6 +60,7 @@ const ProfileOverlay = (props: ProfileOverlayProps) => { const hideAvatars = useSettingsState(state => state.calm.hideAvatars); const hideNicknames = useSettingsState(state => state.calm.hideNicknames); const isOwn = useMemo(() => window.ship === ship, [ship]); + const { copyDisplay, doCopy, didCopy } = useCopy(`~${ship}`); const contact = useContact(`~${ship}`) const color = `#${uxToHex(contact?.color ?? '0x0')}`; @@ -188,9 +190,18 @@ const ProfileOverlay = (props: ProfileOverlayProps) => { overflow='hidden' whiteSpace='pre' marginBottom='0' + cursor='pointer' + display={didCopy ? 'none' : 'block'} + onClick={doCopy} > {showNickname ? contact?.nickname : cite(ship)} + + {copyDisplay} + {isOwn ? ( Date: Wed, 21 Apr 2021 15:46:29 -0400 Subject: [PATCH 14/42] chat: adjust ChatMessage color --- .../apps/chat/components/ChatMessage.tsx | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx b/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx index 306d221ef..82f96e9bc 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx @@ -569,7 +569,7 @@ export const MessagePlaceholder = ({ > From b3f31516d290d00bed2e2c7927be51115cdd7f97 Mon Sep 17 00:00:00 2001 From: James Acklin Date: Wed, 21 Apr 2021 16:21:33 -0400 Subject: [PATCH 15/42] chat: show clickable arrow action on remote image hover --- .../src/views/components/RemoteContent.tsx | 70 ++++++++++++++----- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/pkg/interface/src/views/components/RemoteContent.tsx b/pkg/interface/src/views/components/RemoteContent.tsx index 8e0ee5bf6..557d0c5af 100644 --- a/pkg/interface/src/views/components/RemoteContent.tsx +++ b/pkg/interface/src/views/components/RemoteContent.tsx @@ -48,12 +48,14 @@ class RemoteContent extends Component { this.state = { unfold: props.unfold || false, embed: undefined, - noCors: false + noCors: false, + showArrow: false }; this.unfoldEmbed = this.unfoldEmbed.bind(this); this.loadOembed = this.loadOembed.bind(this); this.wrapInLink = this.wrapInLink.bind(this); this.onError = this.onError.bind(this); + this.toggleArrow = this.toggleArrow.bind(this); } save = () => { @@ -171,6 +173,10 @@ return; this.setState({ noCors: true }); } + toggleArrow() { + this.setState({showArrow: !this.state.showArrow}) + } + render() { const { remoteContentPolicy, @@ -194,21 +200,53 @@ return; if (isImage && remoteContentPolicy.imageShown) { return this.wrapInLink( - , false, false, null, null, true + + { + e.stopPropagation(); + }} + href={url} + > + + + + + + , + false, + false, + null, + null, + true ); } else if (isAudio && remoteContentPolicy.audioShown) { return ( From 9587ccf5cade9ea65edfdcd0415d3cd83ce07d63 Mon Sep 17 00:00:00 2001 From: James Acklin Date: Wed, 21 Apr 2021 16:43:48 -0400 Subject: [PATCH 16/42] links: prevent click in transcluded images, use hovered external arrow --- .../src/views/components/RemoteContent.tsx | 15 +++++++++++---- .../components/Graph/GraphContentWide.tsx | 6 +++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pkg/interface/src/views/components/RemoteContent.tsx b/pkg/interface/src/views/components/RemoteContent.tsx index 557d0c5af..b60db40bd 100644 --- a/pkg/interface/src/views/components/RemoteContent.tsx +++ b/pkg/interface/src/views/components/RemoteContent.tsx @@ -130,7 +130,7 @@ return; }); } - wrapInLink(contents, textOnly = false, unfold = false, unfoldEmbed = null, embedContainer = null, flushPadding = false) { + wrapInLink(contents, textOnly = false, unfold = false, unfoldEmbed = null, embedContainer = null, flushPadding = false, noOp = false) { const { style } = this.props; return ( @@ -148,7 +148,7 @@ return; { e.stopPropagation(); }} + onClick={(e) => { noOp ? e.preventDefault() : e.stopPropagation() }} href={this.props.url} whiteSpace="nowrap" overflow="hidden" @@ -159,7 +159,8 @@ return; style={{ color: 'inherit', textDecoration: 'none', ...style }} target="_blank" rel="noopener noreferrer" - > + cursor={noOp ? 'default' : 'pointer'} + > {contents} @@ -182,6 +183,7 @@ return; remoteContentPolicy, url, text, + transcluded, renderUrl = true, imageProps = {}, audioProps = {}, @@ -198,6 +200,10 @@ return; const isVideo = VIDEO_REGEX.test(url); const isOembed = hasProvider(url); + const isTranscluded = () => { + return transcluded; + } + if (isImage && remoteContentPolicy.imageShown) { return this.wrapInLink( - + ); case "mention": From d05ff8c188c97783d37ef00ea5148bb22df8ea51 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 21 Apr 2021 18:01:56 -0700 Subject: [PATCH 17/42] u3: adds u3s_sift_ud/bytes %ud parser --- pkg/urbit/include/noun/serial.h | 10 +++ pkg/urbit/noun/serial.c | 108 ++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/pkg/urbit/include/noun/serial.h b/pkg/urbit/include/noun/serial.h index f6855a743..dca9e0ac7 100644 --- a/pkg/urbit/include/noun/serial.h +++ b/pkg/urbit/include/noun/serial.h @@ -65,3 +65,13 @@ */ u3_noun u3s_cue_atom(u3_atom a); + + /* u3s_sift_ud_bytes: parse @ud. + */ + u3_weak + u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y); + + /* u3s_sift_ud: parse @ud. + */ + u3_weak + u3s_sift_ud(u3_atom a); diff --git a/pkg/urbit/noun/serial.c b/pkg/urbit/noun/serial.c index dac9970a5..ed15f186d 100644 --- a/pkg/urbit/noun/serial.c +++ b/pkg/urbit/noun/serial.c @@ -856,3 +856,111 @@ u3s_cue_atom(u3_atom a) return u3s_cue_bytes((c3_d)len_w, byt_y); } + +#define NONZERO(a) ( ((a) >= '1') && ((a) <= '9') ) +#define DIGIT(a) ( ((a) >= '0') && ((a) <= '9') ) + +/* u3s_sift_ud_bytes: parse @ud +*/ +u3_weak +u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) +{ + // +ape:ag: just 0 or + // + if ( (1 == len_w) && ('0' == *byt_y) ) { + return (u3_noun)0; + } + + // +ted:ab: leading nonzero, 0-2 digits + // + if ( len_w && NONZERO(*byt_y) ) { + c3_s val_s = *byt_y++ - '0'; + + // 0 digits + // + if ( 0 == --len_w ) return (u3_noun)val_s; + + // 1 digit + // + if ( !DIGIT(*byt_y) ) goto fail; + + val_s *= 10; + val_s += *byt_y++ - '0'; + + if ( 0 == --len_w ) return (u3_noun)val_s; + + // 2 digits + // + if ( !DIGIT(*byt_y) ) goto fail; + + val_s *= 10; + val_s += *byt_y++ - '0'; + + if ( 0 == --len_w ) return (u3_noun)val_s; + + // +tid:ab: dot-prefixed 3-digit blocks + // + if ( 0 != (len_w % 4) ) goto fail; + + { + // XX estimate size, allocate once + // + mpz_t a_mp; + mpz_init_set_ui(a_mp, val_s); + + while ( len_w ) { + if ( ('.' != byt_y[0]) + || !DIGIT(byt_y[1]) + || !DIGIT(byt_y[2]) + || !DIGIT(byt_y[1]) ) + { + mpz_clear(a_mp); + goto fail; + } + + byt_y++; + + val_s = *byt_y++ - '0'; + val_s *= 10; + val_s += *byt_y++ - '0'; + val_s *= 10; + val_s += *byt_y++ - '0'; + + mpz_mul_ui(a_mp, a_mp, 1000); + mpz_add_ui(a_mp, a_mp, val_s); + + len_w -= 4; + } + + return u3i_mp(a_mp); + } + } + +fail: + return u3_none; +} + +#undef DIGIT +#undef NONZERO + + +/* u3s_sift_ud: parse @ud. +*/ +u3_weak +u3s_sift_ud(u3_atom a) +{ + c3_w len_w = u3r_met(3, a); + c3_y* byt_y; + + // XX assumes little-endian + // + if ( c3y == u3a_is_cat(a) ) { + byt_y = (c3_y*)&a; + } + else { + u3a_atom* vat_u = u3a_to_ptr(a); + byt_y = (c3_y*)vat_u->buf_w; + } + + return u3s_sift_ud_bytes(len_w, byt_y); +} From c084dc8c66fa33a1d45c3519208a4b8344b631de Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 21 Apr 2021 18:02:57 -0700 Subject: [PATCH 18/42] u3: replaces overly-lenient %ud parser in +slaw jet --- pkg/urbit/jets/e/slaw.c | 47 ++++++----------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/pkg/urbit/jets/e/slaw.c b/pkg/urbit/jets/e/slaw.c index 2933afb96..c82c38525 100644 --- a/pkg/urbit/jets/e/slaw.c +++ b/pkg/urbit/jets/e/slaw.c @@ -5,49 +5,16 @@ #include -/* functions - */ -u3_noun -_parse_ud(u3_noun txt) { - c3_c* c = u3a_string(txt); +static inline u3_noun +_parse_ud(u3_noun a) +{ + u3_weak pro; - // First character must represent a digit - c3_c* cur = c; - if (cur[0] > '9' || cur[0] < '0') { - u3a_free(c); - return u3_none; - } - u3_atom total = cur[0] - '0'; - cur++; - - int since_last_period = 0; - while (cur[0] != 0) { - since_last_period++; - if (cur[0] == '.') { - since_last_period = 0; - cur++; - continue; - } - - if (cur[0] > '9' || cur[0] < '0') { - u3a_free(c); - u3z(total); - return u3_none; - } - - total = u3ka_mul(total, 10); - total = u3ka_add(total, cur[0] - '0'); - cur++; - - if (since_last_period > 3) { - u3a_free(c); - u3z(total); - return u3_none; - } + if ( u3_none == (pro = u3s_sift_ud(u3x_atom(a))) ) { + return u3_nul; } - u3a_free(c); - return u3nc(0, total); + return u3nc(u3_nul, pro); } static From 5730958d909982f7da1983a46191bc3b88fd5219 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 21 Apr 2021 22:08:39 -0700 Subject: [PATCH 19/42] u3: refactors u3s_sift_ud() control flow --- pkg/urbit/noun/serial.c | 132 ++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 67 deletions(-) diff --git a/pkg/urbit/noun/serial.c b/pkg/urbit/noun/serial.c index ed15f186d..ae6a16236 100644 --- a/pkg/urbit/noun/serial.c +++ b/pkg/urbit/noun/serial.c @@ -857,92 +857,90 @@ u3s_cue_atom(u3_atom a) return u3s_cue_bytes((c3_d)len_w, byt_y); } -#define NONZERO(a) ( ((a) >= '1') && ((a) <= '9') ) -#define DIGIT(a) ( ((a) >= '0') && ((a) <= '9') ) +#define NOT_DEC(a) ( ((a) < '0') || ((a) > '9') ) /* u3s_sift_ud_bytes: parse @ud */ u3_weak u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) { - // +ape:ag: just 0 or + c3_s val_s; + + if ( !len_w ) return u3_none; + + // +ape:ag: just 0 // - if ( (1 == len_w) && ('0' == *byt_y) ) { - return (u3_noun)0; + if ( '0' == *byt_y ) { + return ( 1 == len_w ) ? (u3_noun)0 : u3_none; } + // if ( (1 == len_w) && ('0' == *byt_y) ) return (u3_noun)val_s; + // +ted:ab: leading nonzero, 0-2 digits // - if ( len_w && NONZERO(*byt_y) ) { - c3_s val_s = *byt_y++ - '0'; + if ( NOT_DEC(*byt_y) ) return u3_none; - // 0 digits + val_s = *byt_y++ - '0'; + if ( 0 == --len_w ) return (u3_noun)val_s; + + // 1 digit + // + if ( '.' == *byt_y ) goto tid_ab; + if ( NOT_DEC(*byt_y) ) return u3_none; + + val_s *= 10; + val_s += *byt_y++ - '0'; + if ( 0 == --len_w ) return (u3_noun)val_s; + + // 2 digits + // + if ( '.' == *byt_y ) goto tid_ab; + if ( NOT_DEC(*byt_y) ) return u3_none; + + val_s *= 10; + val_s += *byt_y++ - '0'; + if ( 0 == --len_w ) return (u3_noun)val_s; + +tid_ab: + // +tid:ab: dot-prefixed 3-digit blocks + // + if ( len_w % 4 ) return u3_none; + + { + // XX estimate size, allocate once // - if ( 0 == --len_w ) return (u3_noun)val_s; + mpz_t a_mp; + mpz_init_set_ui(a_mp, val_s); - // 1 digit - // - if ( !DIGIT(*byt_y) ) goto fail; - - val_s *= 10; - val_s += *byt_y++ - '0'; - - if ( 0 == --len_w ) return (u3_noun)val_s; - - // 2 digits - // - if ( !DIGIT(*byt_y) ) goto fail; - - val_s *= 10; - val_s += *byt_y++ - '0'; - - if ( 0 == --len_w ) return (u3_noun)val_s; - - // +tid:ab: dot-prefixed 3-digit blocks - // - if ( 0 != (len_w % 4) ) goto fail; - - { - // XX estimate size, allocate once - // - mpz_t a_mp; - mpz_init_set_ui(a_mp, val_s); - - while ( len_w ) { - if ( ('.' != byt_y[0]) - || !DIGIT(byt_y[1]) - || !DIGIT(byt_y[2]) - || !DIGIT(byt_y[1]) ) - { - mpz_clear(a_mp); - goto fail; - } - - byt_y++; - - val_s = *byt_y++ - '0'; - val_s *= 10; - val_s += *byt_y++ - '0'; - val_s *= 10; - val_s += *byt_y++ - '0'; - - mpz_mul_ui(a_mp, a_mp, 1000); - mpz_add_ui(a_mp, a_mp, val_s); - - len_w -= 4; + while ( len_w ) { + if ( ('.' != byt_y[0]) + || NOT_DEC(byt_y[1]) + || NOT_DEC(byt_y[2]) + || NOT_DEC(byt_y[1]) ) + { + mpz_clear(a_mp); + return u3_none; } - return u3i_mp(a_mp); - } - } + byt_y++; -fail: - return u3_none; + val_s = *byt_y++ - '0'; + val_s *= 10; + val_s += *byt_y++ - '0'; + val_s *= 10; + val_s += *byt_y++ - '0'; + + mpz_mul_ui(a_mp, a_mp, 1000); + mpz_add_ui(a_mp, a_mp, val_s); + + len_w -= 4; + } + + return u3i_mp(a_mp); + } } -#undef DIGIT -#undef NONZERO - +#undef NOT_DEC /* u3s_sift_ud: parse @ud. */ From 39a3d1f26695c5777359d9044cc68e0a0c92dc55 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 21 Apr 2021 22:22:04 -0700 Subject: [PATCH 20/42] u3: updates u3s_sift_ud() to skip gmp allocation where possible --- pkg/urbit/noun/serial.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/pkg/urbit/noun/serial.c b/pkg/urbit/noun/serial.c index ae6a16236..c1db30b76 100644 --- a/pkg/urbit/noun/serial.c +++ b/pkg/urbit/noun/serial.c @@ -864,7 +864,8 @@ u3s_cue_atom(u3_atom a) u3_weak u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) { - c3_s val_s; + c3_s val_s; // leading digits value + c3_y num_y; // leading digits length if ( !len_w ) return u3_none; @@ -880,6 +881,7 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) // if ( NOT_DEC(*byt_y) ) return u3_none; + num_y = 1; val_s = *byt_y++ - '0'; if ( 0 == --len_w ) return (u3_noun)val_s; @@ -888,6 +890,7 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) if ( '.' == *byt_y ) goto tid_ab; if ( NOT_DEC(*byt_y) ) return u3_none; + num_y = 2; val_s *= 10; val_s += *byt_y++ - '0'; if ( 0 == --len_w ) return (u3_noun)val_s; @@ -897,6 +900,7 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) if ( '.' == *byt_y ) goto tid_ab; if ( NOT_DEC(*byt_y) ) return u3_none; + num_y = 3; val_s *= 10; val_s += *byt_y++ - '0'; if ( 0 == --len_w ) return (u3_noun)val_s; @@ -906,6 +910,40 @@ tid_ab: // if ( len_w % 4 ) return u3_none; + // avoid gmp allocation if possible + // + // - 19 decimal digits fit in 64 bits + // - 18 digits is 24 bytes with separators + // + if ( ((1 == num_y) && (24 >= len_w)) + || (20 >= len_w) ) + { + c3_d val_d = val_s; + + while ( len_w ) { + if ( ('.' != byt_y[0]) + || NOT_DEC(byt_y[1]) + || NOT_DEC(byt_y[2]) + || NOT_DEC(byt_y[1]) ) + { + return u3_none; + } + + byt_y++; + + val_d *= 10; + val_d += *byt_y++ - '0'; + val_d *= 10; + val_d += *byt_y++ - '0'; + val_d *= 10; + val_d += *byt_y++ - '0'; + + len_w -= 4; + } + + return u3i_chub(val_d); + } + { // XX estimate size, allocate once // From a2732a039f41d849c8f52aec58b5e45818316ad5 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 21 Apr 2021 22:32:40 -0700 Subject: [PATCH 21/42] u3: cleans up comments in u3s_sift_ud() --- pkg/urbit/noun/serial.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/urbit/noun/serial.c b/pkg/urbit/noun/serial.c index c1db30b76..e22cdc82d 100644 --- a/pkg/urbit/noun/serial.c +++ b/pkg/urbit/noun/serial.c @@ -875,9 +875,7 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) return ( 1 == len_w ) ? (u3_noun)0 : u3_none; } - // if ( (1 == len_w) && ('0' == *byt_y) ) return (u3_noun)val_s; - - // +ted:ab: leading nonzero, 0-2 digits + // +ted:ab: leading nonzero, 0-2 additional digits // if ( NOT_DEC(*byt_y) ) return u3_none; @@ -885,7 +883,7 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) val_s = *byt_y++ - '0'; if ( 0 == --len_w ) return (u3_noun)val_s; - // 1 digit + // 1 additional digit // if ( '.' == *byt_y ) goto tid_ab; if ( NOT_DEC(*byt_y) ) return u3_none; @@ -895,7 +893,7 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) val_s += *byt_y++ - '0'; if ( 0 == --len_w ) return (u3_noun)val_s; - // 2 digits + // 2 additional digits // if ( '.' == *byt_y ) goto tid_ab; if ( NOT_DEC(*byt_y) ) return u3_none; From 8532c0c362445db047c1c9ae244aafccbed20c4a Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Thu, 22 Apr 2021 17:48:24 -0400 Subject: [PATCH 22/42] landscape: restore timestamps across interface --- .../src/views/apps/links/components/LinkItem.tsx | 6 ++++-- pkg/interface/src/views/apps/publish/components/Note.tsx | 3 ++- pkg/interface/src/views/components/Author.tsx | 9 ++++++--- pkg/interface/src/views/components/CommentItem.tsx | 1 + pkg/interface/src/views/components/Timestamp.tsx | 1 + .../components/Home/Post/PostItem/PostHeader.js | 1 + 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/interface/src/views/apps/links/components/LinkItem.tsx b/pkg/interface/src/views/apps/links/components/LinkItem.tsx index a3e206543..aa1506454 100644 --- a/pkg/interface/src/views/apps/links/components/LinkItem.tsx +++ b/pkg/interface/src/views/apps/links/components/LinkItem.tsx @@ -19,7 +19,7 @@ interface LinkItemProps { node: GraphNode; association: Association; resource: string; api: GlobalApi; group: Group; path: string; } -export const LinkItem = (props: LinkItemProps): ReactElement => { +export const LinkItem = (props: LinkItemProps): ReactElement => { const { association, node, @@ -86,7 +86,7 @@ export const LinkItem = (props: LinkItemProps): ReactElement => { permalink, 'Copy reference' ); - + const deleteLink = () => { if (confirm('Are you sure you want to delete this link?')) { api.graph.removeNodes(`~${ship}`, name, [node.post.index]); @@ -167,9 +167,11 @@ export const LinkItem = (props: LinkItemProps): ReactElement => { - + {copyDisplay} {adminLinks} diff --git a/pkg/interface/src/views/components/Author.tsx b/pkg/interface/src/views/components/Author.tsx index 41d0fb723..11b002149 100644 --- a/pkg/interface/src/views/components/Author.tsx +++ b/pkg/interface/src/views/components/Author.tsx @@ -24,6 +24,7 @@ interface AuthorProps { unread?: boolean; api?: GlobalApi; size?: number; + lineHeight?: string; } // eslint-disable-next-line max-lines-per-function @@ -38,10 +39,11 @@ export default function Author(props: AuthorProps & PropFunc): React group, isRelativeTime, dontShowTime, + lineHeight = 'tall', ...rest } = props; - const time = props.time || false; + const time = props.time || props.date || false; const size = props.size || 16; const sigilPadding = props.sigilPadding || 2; @@ -89,7 +91,7 @@ export default function Author(props: AuthorProps & PropFunc): React ) : sigil; return ( - + { e.stopPropagation(); @@ -110,7 +112,7 @@ export default function Author(props: AuthorProps & PropFunc): React color='black' fontSize='1' cursor='pointer' - lineHeight='tall' + lineHeight={lineHeight} fontFamily={showNickname ? 'sans' : 'mono'} fontWeight={showNickname ? '500' : '400'} mr={showNickname ? 0 : "2px"} @@ -121,6 +123,7 @@ export default function Author(props: AuthorProps & PropFunc): React { !dontShowTime && time && ( {copyDisplay} diff --git a/pkg/interface/src/views/components/Timestamp.tsx b/pkg/interface/src/views/components/Timestamp.tsx index 6b5599630..1023031f5 100644 --- a/pkg/interface/src/views/components/Timestamp.tsx +++ b/pkg/interface/src/views/components/Timestamp.tsx @@ -12,6 +12,7 @@ export type TimestampProps = BoxProps & { date?: boolean; time?: boolean; relative?: boolean; + height?: string; }; const Timestamp = (props: TimestampProps): ReactElement | null => { diff --git a/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostHeader.js b/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostHeader.js index fdf80d171..3374bee2f 100644 --- a/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostHeader.js +++ b/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostHeader.js @@ -46,6 +46,7 @@ export function PostHeader(props) { isRelativeTime={true} showTime={false} time={true} + lineHeight='1' /> Date: Thu, 22 Apr 2021 15:12:55 -0700 Subject: [PATCH 23/42] u3: fix typo in u3s_sift_bytes() block conditionals --- pkg/urbit/noun/serial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/urbit/noun/serial.c b/pkg/urbit/noun/serial.c index e22cdc82d..a63288ccb 100644 --- a/pkg/urbit/noun/serial.c +++ b/pkg/urbit/noun/serial.c @@ -922,7 +922,7 @@ tid_ab: if ( ('.' != byt_y[0]) || NOT_DEC(byt_y[1]) || NOT_DEC(byt_y[2]) - || NOT_DEC(byt_y[1]) ) + || NOT_DEC(byt_y[3]) ) { return u3_none; } @@ -952,7 +952,7 @@ tid_ab: if ( ('.' != byt_y[0]) || NOT_DEC(byt_y[1]) || NOT_DEC(byt_y[2]) - || NOT_DEC(byt_y[1]) ) + || NOT_DEC(byt_y[3]) ) { mpz_clear(a_mp); return u3_none; From 1ca0207b208a6b197df628fe6a6abc4cd8b46683 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 22 Apr 2021 15:42:03 -0700 Subject: [PATCH 24/42] u3: adds basic tests for u3s_sift_ud() --- pkg/urbit/tests/jet_tests.c | 106 ++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/pkg/urbit/tests/jet_tests.c b/pkg/urbit/tests/jet_tests.c index 852746e5b..b248e05e6 100644 --- a/pkg/urbit/tests/jet_tests.c +++ b/pkg/urbit/tests/jet_tests.c @@ -9,6 +9,107 @@ _setup(void) u3m_pave(c3y); } +static inline c3_i +_ud_good(c3_w num_w, const c3_c* num_c) +{ + u3_weak out; + if ( num_w != (out = u3s_sift_ud_bytes(strlen(num_c), (c3_y*)num_c)) ) { + if ( u3_none == out ) { + fprintf(stderr, "sift_ud: %s fail; expected %u\r\n", num_c, num_w); + } + else { + fprintf(stderr, "sift_ud: %s wrong; expected %u: actual %u\r\n", num_c, num_w, out); + } + return 0; + } + + return 1; +} + +static inline c3_i +_ud_fail(const c3_c* num_c) +{ + u3_weak out; + if ( u3_none != (out = u3s_sift_ud_bytes(strlen(num_c), (c3_y*)num_c)) ) { + u3m_p("out", out); + fprintf(stderr, "sift_ud: %s expected fail\r\n", num_c); + return 0; + } + + return 1; +} + +static c3_i +_test_sift_ud(void) +{ + c3_i ret_i = 1; + + ret_i &= _ud_good(0, "0"); + ret_i &= _ud_good(1, "1"); + ret_i &= _ud_good(12, "12"); + ret_i &= _ud_good(123, "123"); + ret_i &= _ud_good(1234, "1.234"); + ret_i &= _ud_good(12345, "12.345"); + ret_i &= _ud_good(123456, "123.456"); + ret_i &= _ud_good(1234567, "1.234.567"); + ret_i &= _ud_good(12345678, "12.345.678"); + ret_i &= _ud_good(123456789, "123.456.789"); + ret_i &= _ud_good(100000000, "100.000.000"); + ret_i &= _ud_good(101101101, "101.101.101"); + ret_i &= _ud_good(201201201, "201.201.201"); + ret_i &= _ud_good(302201100, "302.201.100"); + + ret_i &= _ud_fail("01"); + ret_i &= _ud_fail("02"); + ret_i &= _ud_fail("003"); + ret_i &= _ud_fail("1234"); + ret_i &= _ud_fail("1234.5"); + ret_i &= _ud_fail("1234.567.8"); + ret_i &= _ud_fail("1234.56..78."); + ret_i &= _ud_fail("123.45a"); + + { + c3_c* num_c = "4.294.967.296"; + u3_weak out = u3s_sift_ud_bytes(strlen(num_c), (c3_y*)num_c); + u3_atom pro = u3qc_bex(32); + + if ( u3_none == out ) { + fprintf(stderr, "sift_ud: (bex 32) fail\r\n"); + ret_i = 0; + } + + if ( c3n == u3r_sing(pro, out) ) { + u3m_p("out", out); + fprintf(stderr, "sift_ud: (bex 32) wrong\r\n"); + ret_i = 0; + } + + u3z(out); u3z(pro); + } + + + { + c3_c* num_c = "340.282.366.920.938.463.463.374.607.431.768.211.456"; + u3_weak out = u3s_sift_ud_bytes(strlen(num_c), (c3_y*)num_c); + u3_atom pro = u3qc_bex(128); + + if ( u3_none == out ) { + fprintf(stderr, "sift_ud: (bex 128) fail\r\n"); + ret_i = 0; + } + + if ( c3n == u3r_sing(pro, out) ) { + u3m_p("out", out); + fprintf(stderr, "sift_ud: (bex 128) wrong\r\n"); + ret_i = 0; + } + + u3z(out); u3z(pro); + } + + return ret_i; +} + static c3_i _test_en_base16(void) { @@ -400,6 +501,11 @@ _test_jets(void) { c3_i ret_i = 1; + if ( !_test_sift_ud() ) { + fprintf(stderr, "test jets: sift_ud: failed\r\n"); + ret_i = 0; + } + if ( !_test_base16() ) { fprintf(stderr, "test jets: base16: failed\r\n"); ret_i = 0; From af1325a3878bf68f487893f7dcc94fb23b7578a1 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 22 Apr 2021 15:53:42 -0700 Subject: [PATCH 25/42] u3: simplies leading-digit control flow in u3s_sift_ud() --- pkg/urbit/noun/serial.c | 86 +++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 54 deletions(-) diff --git a/pkg/urbit/noun/serial.c b/pkg/urbit/noun/serial.c index a63288ccb..6efc48e61 100644 --- a/pkg/urbit/noun/serial.c +++ b/pkg/urbit/noun/serial.c @@ -857,61 +857,48 @@ u3s_cue_atom(u3_atom a) return u3s_cue_bytes((c3_d)len_w, byt_y); } -#define NOT_DEC(a) ( ((a) < '0') || ((a) > '9') ) +#define DIGIT(a) ( ((a) >= '0') && ((a) <= '9') ) +#define BLOCK(a) ( ('.' == (a)[0]) \ + && DIGIT(a[1]) \ + && DIGIT(a[2]) \ + && DIGIT(a[3]) ) /* u3s_sift_ud_bytes: parse @ud */ u3_weak u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) { - c3_s val_s; // leading digits value - c3_y num_y; // leading digits length - - if ( !len_w ) return u3_none; + c3_y num_y = len_w % 4; // leading digits length + c3_s val_s = 0; // leading digits value // +ape:ag: just 0 // - if ( '0' == *byt_y ) { - return ( 1 == len_w ) ? (u3_noun)0 : u3_none; + if ( !len_w ) return u3_none; + else if ( '0' == *byt_y ) return ( 1 == len_w ) ? (u3_noun)0 : u3_none; + + // +ted:ab: leading nonzero (checked above), plus 0-2 digits + // + switch (num_y) { + case 3: if ( !DIGIT(*byt_y) ) return u3_none; + val_s *= 10; + val_s += *byt_y++ - '0'; + + case 2: if ( !DIGIT(*byt_y) ) return u3_none; + val_s *= 10; + val_s += *byt_y++ - '0'; + + case 1: if ( !DIGIT(*byt_y) ) return u3_none; + val_s *= 10; + val_s += *byt_y++ - '0'; } - // +ted:ab: leading nonzero, 0-2 additional digits - // - if ( NOT_DEC(*byt_y) ) return u3_none; + len_w -= num_y; - num_y = 1; - val_s = *byt_y++ - '0'; - if ( 0 == --len_w ) return (u3_noun)val_s; - - // 1 additional digit - // - if ( '.' == *byt_y ) goto tid_ab; - if ( NOT_DEC(*byt_y) ) return u3_none; - - num_y = 2; - val_s *= 10; - val_s += *byt_y++ - '0'; - if ( 0 == --len_w ) return (u3_noun)val_s; - - // 2 additional digits - // - if ( '.' == *byt_y ) goto tid_ab; - if ( NOT_DEC(*byt_y) ) return u3_none; - - num_y = 3; - val_s *= 10; - val_s += *byt_y++ - '0'; - if ( 0 == --len_w ) return (u3_noun)val_s; - -tid_ab: // +tid:ab: dot-prefixed 3-digit blocks // - if ( len_w % 4 ) return u3_none; - - // avoid gmp allocation if possible - // - // - 19 decimal digits fit in 64 bits - // - 18 digits is 24 bytes with separators + // avoid gmp allocation if possible + // - 19 decimal digits fit in 64 bits + // - 18 digits is 24 bytes with separators // if ( ((1 == num_y) && (24 >= len_w)) || (20 >= len_w) ) @@ -919,13 +906,7 @@ tid_ab: c3_d val_d = val_s; while ( len_w ) { - if ( ('.' != byt_y[0]) - || NOT_DEC(byt_y[1]) - || NOT_DEC(byt_y[2]) - || NOT_DEC(byt_y[3]) ) - { - return u3_none; - } + if ( !BLOCK(byt_y) ) return u3_none; byt_y++; @@ -949,11 +930,7 @@ tid_ab: mpz_init_set_ui(a_mp, val_s); while ( len_w ) { - if ( ('.' != byt_y[0]) - || NOT_DEC(byt_y[1]) - || NOT_DEC(byt_y[2]) - || NOT_DEC(byt_y[3]) ) - { + if ( !BLOCK(byt_y) ) { mpz_clear(a_mp); return u3_none; } @@ -976,7 +953,8 @@ tid_ab: } } -#undef NOT_DEC +#undef BLOCK +#undef DIGIT /* u3s_sift_ud: parse @ud. */ From 9c550a679522b9604c62319726d815aae0b64ca4 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 22 Apr 2021 15:54:19 -0700 Subject: [PATCH 26/42] u3: shortcircuit direct atoms in u3i_chub() --- pkg/urbit/noun/imprison.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/urbit/noun/imprison.c b/pkg/urbit/noun/imprison.c index e3603812c..77feae7f6 100644 --- a/pkg/urbit/noun/imprison.c +++ b/pkg/urbit/noun/imprison.c @@ -313,12 +313,17 @@ u3i_word(c3_w dat_w) u3_atom u3i_chub(c3_d dat_d) { - c3_w dat_w[2] = { - dat_d & 0xffffffffULL, - dat_d >> 32 - }; + if ( c3y == u3a_is_cat(dat_d) ) { + return (u3_atom)dat_d; + } + else { + c3_w dat_w[2] = { + dat_d & 0xffffffffULL, + dat_d >> 32 + }; - return u3i_words(2, dat_w); + return u3i_words(2, dat_w); + } } /* u3i_bytes(): Copy [a] bytes from [b] to an LSB first atom. From 64a96acb20625479174820a920811fc0b53b5f2e Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 22 Apr 2021 16:07:35 -0700 Subject: [PATCH 27/42] u3: requires at least one leading digit in u3s_sift_ud() --- pkg/urbit/noun/serial.c | 7 +++++-- pkg/urbit/tests/jet_tests.c | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/urbit/noun/serial.c b/pkg/urbit/noun/serial.c index 6efc48e61..d6a8ae8c0 100644 --- a/pkg/urbit/noun/serial.c +++ b/pkg/urbit/noun/serial.c @@ -876,9 +876,9 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) if ( !len_w ) return u3_none; else if ( '0' == *byt_y ) return ( 1 == len_w ) ? (u3_noun)0 : u3_none; - // +ted:ab: leading nonzero (checked above), plus 0-2 digits + // +ted:ab: leading nonzero (checked above), plus up to 2 digits // - switch (num_y) { + switch ( num_y ) { case 3: if ( !DIGIT(*byt_y) ) return u3_none; val_s *= 10; val_s += *byt_y++ - '0'; @@ -890,6 +890,9 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) case 1: if ( !DIGIT(*byt_y) ) return u3_none; val_s *= 10; val_s += *byt_y++ - '0'; + break; + + case 0: return u3_none; } len_w -= num_y; diff --git a/pkg/urbit/tests/jet_tests.c b/pkg/urbit/tests/jet_tests.c index b248e05e6..2e96f2305 100644 --- a/pkg/urbit/tests/jet_tests.c +++ b/pkg/urbit/tests/jet_tests.c @@ -67,6 +67,7 @@ _test_sift_ud(void) ret_i &= _ud_fail("1234.567.8"); ret_i &= _ud_fail("1234.56..78."); ret_i &= _ud_fail("123.45a"); + ret_i &= _ud_fail(".123.456"); { c3_c* num_c = "4.294.967.296"; From 1600e71daffda25ac5f6d82e55804726a4e9820e Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 22 Apr 2021 16:17:56 -0700 Subject: [PATCH 28/42] u3: adds a macro for leading digits in u3s_sift_ud() --- pkg/urbit/noun/serial.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/pkg/urbit/noun/serial.c b/pkg/urbit/noun/serial.c index d6a8ae8c0..c2ba6fefb 100644 --- a/pkg/urbit/noun/serial.c +++ b/pkg/urbit/noun/serial.c @@ -878,23 +878,21 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) // +ted:ab: leading nonzero (checked above), plus up to 2 digits // +#define NEXT() do { \ + if ( !DIGIT(*byt_y) ) return u3_none; \ + val_s *= 10; \ + val_s += *byt_y++ - '0'; \ + } while (0) + switch ( num_y ) { - case 3: if ( !DIGIT(*byt_y) ) return u3_none; - val_s *= 10; - val_s += *byt_y++ - '0'; - - case 2: if ( !DIGIT(*byt_y) ) return u3_none; - val_s *= 10; - val_s += *byt_y++ - '0'; - - case 1: if ( !DIGIT(*byt_y) ) return u3_none; - val_s *= 10; - val_s += *byt_y++ - '0'; - break; - - case 0: return u3_none; + case 3: NEXT(); + case 2: NEXT(); + case 1: NEXT(); break; + case 0: return u3_none; } +#undef NEXT + len_w -= num_y; // +tid:ab: dot-prefixed 3-digit blocks From 0681c9a477d226a3574fab9bd9db07487b04df01 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 22 Apr 2021 17:26:36 -0700 Subject: [PATCH 29/42] u3: avoid gmp realloc in u3s_sift_ud() --- pkg/urbit/noun/serial.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/urbit/noun/serial.c b/pkg/urbit/noun/serial.c index c2ba6fefb..db00bb1da 100644 --- a/pkg/urbit/noun/serial.c +++ b/pkg/urbit/noun/serial.c @@ -925,10 +925,14 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) } { - // XX estimate size, allocate once + // avoid gmp realloc if possible // mpz_t a_mp; - mpz_init_set_ui(a_mp, val_s); + { + c3_d bit_d = (c3_d)(len_w / 4) * 10; + mpz_init2(a_mp, (c3_w)c3_min(bit_d, UINT32_MAX)); + mpz_set_ui(a_mp, val_s); + } while ( len_w ) { if ( !BLOCK(byt_y) ) { From 45ef57ab1a787da177b3c484a3c3361b0005b3f2 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 22 Apr 2021 17:34:49 -0700 Subject: [PATCH 30/42] u3: refactors gmp initialization in u3r_mp() --- pkg/urbit/noun/retrieve.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/urbit/noun/retrieve.c b/pkg/urbit/noun/retrieve.c index 874b73d87..f5a74e4dc 100644 --- a/pkg/urbit/noun/retrieve.c +++ b/pkg/urbit/noun/retrieve.c @@ -1205,16 +1205,11 @@ u3r_mp(mpz_t a_mp, else { u3a_atom* b_u = u3a_to_ptr(b); c3_w len_w = b_u->len_w; + c3_d bit_d = (c3_d)len_w << 5; // avoid reallocation on import, if possible // - if ( (len_w >> 27) ) { - mpz_init(a_mp); - } - else { - mpz_init2(a_mp, len_w << 5); - } - + mpz_init2(a_mp, (c3_w)c3_min(bit_d, UINT32_MAX)); mpz_import(a_mp, len_w, -1, sizeof(c3_w), 0, 0, b_u->buf_w); } } From 715b42bb42557b8cbd6f38a0adf56ce035ca8d4a Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 22 Apr 2021 20:14:28 -0700 Subject: [PATCH 31/42] u3: tweaks u3s_sift_ud() conditional style --- pkg/urbit/noun/serial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/urbit/noun/serial.c b/pkg/urbit/noun/serial.c index db00bb1da..6480d2741 100644 --- a/pkg/urbit/noun/serial.c +++ b/pkg/urbit/noun/serial.c @@ -873,8 +873,8 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) // +ape:ag: just 0 // - if ( !len_w ) return u3_none; - else if ( '0' == *byt_y ) return ( 1 == len_w ) ? (u3_noun)0 : u3_none; + if ( !len_w ) return u3_none; + if ( '0' == *byt_y ) return ( 1 == len_w ) ? (u3_noun)0 : u3_none; // +ted:ab: leading nonzero (checked above), plus up to 2 digits // From 48837a1fbe5494251798e5c46a0449e7f8468cfd Mon Sep 17 00:00:00 2001 From: pilfer-pandex <47340789+pilfer-pandex@users.noreply.github.com> Date: Thu, 8 Apr 2021 18:37:09 -0400 Subject: [PATCH 32/42] king: ames: make udp serv reuse port on err --- pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs | 40 ++++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs b/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs index f38b1a868..1c9ea2867 100644 --- a/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs +++ b/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs @@ -5,7 +5,8 @@ - If can't open the port, wait and try again repeatedly. - If there is an error reading or writting from the open socket, - close it and open another. + close it and open another, making sure, however, to reuse the + same port 2. Receives packets from the socket. @@ -158,7 +159,7 @@ realUdpServ -> HostAddress -> AmesStat -> RIO e UdpServ -realUdpServ por hos sat = do +realUdpServ startPort hos sat = do logInfo $ displayShow ("AMES", "UDP", "Starting real UDP server.") env <- ask @@ -202,23 +203,30 @@ realUdpServ por hos sat = do did <- atomically (tryWriteTBQueue qSend (a, b)) when (did == False) $ do logWarn "AMES: UDP: Dropping outbound packet because queue is full." + let opener por = do + logInfo $ displayShow $ ("AMES", "UDP", "Trying to open socket, port",) + por + sk <- forceBind por hos + sn <- io $ getSocketName sk + sp <- io $ socketPort sk + logInfo $ displayShow $ ("AMES", "UDP", "Got socket", sn, sp) - tOpen <- async $ forever $ do - sk <- forceBind por hos - sn <- io $ getSocketName sk + let waitForRelease = do + atomically (writeTVar vSock (Just sk)) + broken <- atomically (takeTMVar vFail) + logWarn "AMES: UDP: Closing broken socket." + io (close broken) - let waitForRelease = do - atomically (writeTVar vSock (Just sk)) - broken <- atomically (takeTMVar vFail) - logWarn "AMES: UDP: Closing broken socket." - io (close broken) + case sn of + (SockAddrInet boundPort _) -> + -- When we're on IPv4, maybe port forward at the NAT. + rwith (requestPortAccess $ fromIntegral boundPort) $ + \() -> waitForRelease + _ -> waitForRelease - case sn of - (SockAddrInet boundPort _) -> - -- When we're on IPv4, maybe port forward at the NAT. - rwith (requestPortAccess $ fromIntegral boundPort) $ - \() -> waitForRelease - _ -> waitForRelease + opener sp + + tOpen <- async $ opener startPort tSend <- async $ forever $ join $ atomically $ do (adr, byt) <- readTBQueue qSend From 17bf33d3a04eb43054464a011ed7fa8c82ffd356 Mon Sep 17 00:00:00 2001 From: pilfer-pandex <47340789+pilfer-pandex@users.noreply.github.com> Date: Thu, 8 Apr 2021 21:03:21 -0400 Subject: [PATCH 33/42] king: fix byte order of Ipv4 --- pkg/hs/urbit-king/lib/Urbit/Arvo/Common.hs | 45 +++++++++++++------ .../urbit-king/lib/Urbit/Vere/Ames/Packet.hs | 9 ++-- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/pkg/hs/urbit-king/lib/Urbit/Arvo/Common.hs b/pkg/hs/urbit-king/lib/Urbit/Arvo/Common.hs index cb30b0196..e717b24fb 100644 --- a/pkg/hs/urbit-king/lib/Urbit/Arvo/Common.hs +++ b/pkg/hs/urbit-king/lib/Urbit/Arvo/Common.hs @@ -29,6 +29,7 @@ import Data.Bits import Data.Serialize import qualified Network.HTTP.Types.Method as H +import qualified Network.Socket as N import qualified Urbit.Ob as Ob @@ -159,6 +160,19 @@ deriveNoun ''JsonNode -- Ames Destinations ------------------------------------------------- +serializeToNoun :: Serialize a => a -> Noun +serializeToNoun = A . bytesAtom . encode + +serializeParseNoun :: Serialize a => String -> Int -> Noun -> Parser a +serializeParseNoun desc len = named (pack desc) . \case + A (atomBytes -> bs) + -- Atoms lose leading 0s, but since lsb, these become trailing NULs + | length bs <= len -> case decode $ bs <> replicate (len - length bs) 0 of + Right aa -> pure aa + Left msg -> fail msg + | otherwise -> fail ("putative " <> desc <> " " <> show bs <> " too long") + C{} -> fail ("unexpected cell in " <> desc) + newtype Patp a = Patp { unPatp :: a } deriving newtype (Eq, Ord, Enum, Real, Integral, Num, ToNoun, FromNoun) @@ -167,8 +181,19 @@ newtype Port = Port { unPort :: Word16 } deriving newtype (Eq, Ord, Show, Enum, Real, Integral, Num, ToNoun, FromNoun) -- @if -newtype Ipv4 = Ipv4 { unIpv4 :: Word32 } - deriving newtype (Eq, Ord, Enum, Real, Integral, Num, ToNoun, FromNoun) +newtype Ipv4 = Ipv4 { unIpv4 :: N.HostAddress } + deriving newtype (Eq, Ord, Enum) + +instance Serialize Ipv4 where + get = Ipv4 <$> N.tupleToHostAddress + <$> ((,,,) <$> getWord8 <*> getWord8 <*> getWord8 <*> getWord8) + put (Ipv4 (N.hostAddressToTuple -> (a, b, c, d))) = for_ [a, b, c, d] putWord8 + +instance ToNoun Ipv4 where + toNoun = serializeToNoun + +instance FromNoun Ipv4 where + parseNoun = serializeParseNoun "Ipv4" 4 instance Show Ipv4 where show (Ipv4 i) = @@ -178,6 +203,7 @@ instance Show Ipv4 where show (i .&. 0xff) -- @is +-- should probably use hostAddress6ToTuple here, but no one uses it right now newtype Ipv6 = Ipv6 { unIpv6 :: Word128 } deriving newtype (Eq, Ord, Show, Enum, Real, Integral, Num, ToNoun, FromNoun) @@ -190,21 +216,14 @@ data AmesAddress = AAIpv4 Ipv4 Port deriving (Eq, Ord, Show) instance Serialize AmesAddress where - get = AAIpv4 <$> (Ipv4 <$> getWord32le) <*> (Port <$> getWord16le) - put (AAIpv4 (Ipv4 ip) (Port port)) = putWord32le ip >> putWord16le port + get = AAIpv4 <$> get <*> (Port <$> getWord16le) + put (AAIpv4 ip (Port port)) = put ip >> putWord16le port instance FromNoun AmesAddress where - parseNoun = named "AmesAddress" . \case - A (atomBytes -> bs) - -- Atoms lose leading 0s, but since lsb, these become trailing NULs - | length bs <= 6 -> case decode $ bs <> replicate (6 - length bs) 0 of - Right aa -> pure aa - Left msg -> fail msg - | otherwise -> fail ("putative address " <> show bs <> " too long") - C{} -> fail "unexpected cell in ames address" + parseNoun = serializeParseNoun "AmesAddress" 6 instance ToNoun AmesAddress where - toNoun = A . bytesAtom . encode + toNoun = serializeToNoun type AmesDest = Each Galaxy AmesAddress diff --git a/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/Packet.hs b/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/Packet.hs index 8c90bd169..d2ddcdfc4 100644 --- a/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/Packet.hs +++ b/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/Packet.hs @@ -80,10 +80,6 @@ data ShipClass muk :: ByteString -> Word20 muk bs = mugBS bs .&. (2 ^ 20 - 1) --- XX check this -getAmesAddress :: Get AmesAddress -getAmesAddress = AAIpv4 <$> (Ipv4 <$> getWord32le) <*> (Port <$> getWord16le) - putAmesAddress :: Putter AmesAddress putAmesAddress = \case AAIpv4 (Ipv4 ip) (Port port) -> putWord32le ip >> putWord16le port @@ -104,7 +100,7 @@ instance Serialize Packet where guard isAmes pktOrigin <- if isRelayed - then Just <$> getAmesAddress + then Just <$> get else pure Nothing -- body @@ -157,9 +153,10 @@ instance Serialize Packet where putWord32le head case pktOrigin of - Just o -> putAmesAddress o + Just o -> put o Nothing -> pure () putByteString body + where putShipGetRank s@(Ship (LargeKey p q)) = case () of _ | s < 2 ^ 16 -> (0, putWord16le $ fromIntegral s) -- lord From 0bcc83f40c3c7209b09794d43952852b9734c486 Mon Sep 17 00:00:00 2001 From: pilfer-pandex <47340789+pilfer-pandex@users.noreply.github.com> Date: Mon, 12 Apr 2021 13:12:37 -0400 Subject: [PATCH 34/42] king: my god, actually reverse ip addrs --- pkg/hs/urbit-king/lib/Urbit/Arvo/Common.hs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pkg/hs/urbit-king/lib/Urbit/Arvo/Common.hs b/pkg/hs/urbit-king/lib/Urbit/Arvo/Common.hs index e717b24fb..3168ba1e3 100644 --- a/pkg/hs/urbit-king/lib/Urbit/Arvo/Common.hs +++ b/pkg/hs/urbit-king/lib/Urbit/Arvo/Common.hs @@ -25,7 +25,6 @@ module Urbit.Arvo.Common import Urbit.Prelude import Control.Monad.Fail (fail) -import Data.Bits import Data.Serialize import qualified Network.HTTP.Types.Method as H @@ -185,9 +184,9 @@ newtype Ipv4 = Ipv4 { unIpv4 :: N.HostAddress } deriving newtype (Eq, Ord, Enum) instance Serialize Ipv4 where - get = Ipv4 <$> N.tupleToHostAddress - <$> ((,,,) <$> getWord8 <*> getWord8 <*> getWord8 <*> getWord8) - put (Ipv4 (N.hostAddressToTuple -> (a, b, c, d))) = for_ [a, b, c, d] putWord8 + get = (\a b c d -> Ipv4 $ N.tupleToHostAddress $ (d, c, b, a)) + <$> getWord8 <*> getWord8 <*> getWord8 <*> getWord8 + put (Ipv4 (N.hostAddressToTuple -> (a, b, c, d))) = for_ [d, c, b, a] putWord8 instance ToNoun Ipv4 where toNoun = serializeToNoun @@ -196,11 +195,11 @@ instance FromNoun Ipv4 where parseNoun = serializeParseNoun "Ipv4" 4 instance Show Ipv4 where - show (Ipv4 i) = - show ((shiftR i 24) .&. 0xff) ++ "." ++ - show ((shiftR i 16) .&. 0xff) ++ "." ++ - show ((shiftR i 8) .&. 0xff) ++ "." ++ - show (i .&. 0xff) + show (Ipv4 (N.hostAddressToTuple -> (a, b, c, d))) = + show a ++ "." ++ + show b ++ "." ++ + show c ++ "." ++ + show d -- @is -- should probably use hostAddress6ToTuple here, but no one uses it right now From dad455365ddcb9817a7535566c436a7a37b3f35c Mon Sep 17 00:00:00 2001 From: pilfer-pandex <47340789+pilfer-pandex@users.noreply.github.com> Date: Fri, 23 Apr 2021 15:49:40 -0400 Subject: [PATCH 35/42] king: add requested disclamer to UDP.hs --- pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs b/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs index 1c9ea2867..8a740d7bd 100644 --- a/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs +++ b/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs @@ -7,6 +7,9 @@ - If there is an error reading or writting from the open socket, close it and open another, making sure, however, to reuse the same port + NOTE: It's not clear what, if anything, closing and reopening + the socket does. We're keeping this behavior out of conservatism + until we understand it better. 2. Receives packets from the socket. From 47c8075294e8be08477314994145e4a5174e6e4c Mon Sep 17 00:00:00 2001 From: James Acklin Date: Sat, 24 Apr 2021 21:42:21 -0400 Subject: [PATCH 36/42] chat: threshold send button & chatinput fixes --- .../views/apps/chat/components/ChatInput.tsx | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx index dab2c1169..2ad4cab26 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx @@ -9,7 +9,7 @@ import GlobalApi from '~/logic/api/global'; import { Envelope } from '~/types/chat-update'; import { StorageState } from '~/types'; import { Contacts, Content } from '@urbit/api'; -import { Row, BaseImage, Box, Icon, LoadingSpinner } from '@tlon/indigo-react'; +import { Row, BaseImage, Box, Icon, LoadingSpinner, Text } from '@tlon/indigo-react'; import withStorage from '~/views/components/withStorage'; import { withLocalState } from '~/logic/state/local'; @@ -182,7 +182,15 @@ class ChatInput extends Component { onPaste={this.onPaste.bind(this)} placeholder='Message...' /> - + + + + {this.props.canUpload ? ( this.props.uploading ? ( @@ -199,13 +207,15 @@ class ChatInput extends Component { ) ) : null} - - + + console.log(this.chatEditor.current.submit())} + > + Send + ); From 1d5cff849d56bf061fef57fdb66b8eec0f97ef8f Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Sun, 25 Apr 2021 15:45:51 -0400 Subject: [PATCH 37/42] landscape: highlight content with our mentions --- .../src/views/apps/chat/components/ChatMessage.tsx | 12 +++++++++++- pkg/interface/src/views/components/CommentItem.tsx | 13 ++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx b/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx index 776a3c745..3bbb8f5d3 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx @@ -264,6 +264,7 @@ class ChatMessage extends Component { componentDidMount() {} render() { + let { highlighted } = this.props; const { msg, previousMsg, @@ -279,12 +280,21 @@ class ChatMessage extends Component { unreadMarkerRef, history, api, - highlighted, showOurContact, fontSize, hideHover } = this.props; + const ourMention = msg?.contents?.some((e) => { + return e?.mention && e?.mention === window.ship; + }); + + if (!highlighted) { + if (ourMention) { + highlighted = true; + } + } + let onReply = this.props?.onReply ?? (() => {}); const transcluded = this.props?.transcluded ?? 0; let { renderSigil } = this.props; diff --git a/pkg/interface/src/views/components/CommentItem.tsx b/pkg/interface/src/views/components/CommentItem.tsx index f65273189..c314f987f 100644 --- a/pkg/interface/src/views/components/CommentItem.tsx +++ b/pkg/interface/src/views/components/CommentItem.tsx @@ -35,6 +35,7 @@ interface CommentItemProps { } export function CommentItem(props: CommentItemProps): ReactElement { + let { highlighted } = props; const { ship, name, api, comment, group } = props; const association = useMetadataState( useCallback(s => s.associations.graph[`/ship/${ship}/${name}`], [ship,name]) @@ -47,6 +48,16 @@ export function CommentItem(props: CommentItemProps): ReactElement { await api.graph.removeNodes(ship, name, [comment.post?.index]); }; + const ourMention = post?.contents?.some((e) => { + return e?.mention && e?.mention === window.ship; + }); + + if (!highlighted) { + if (ourMention) { + highlighted = true; + } + } + const commentIndexArray = (comment.post?.index || '/').split('/'); const commentIndex = commentIndexArray[commentIndexArray.length - 1]; @@ -106,7 +117,7 @@ export function CommentItem(props: CommentItemProps): ReactElement { borderRadius="1" p="1" mb="1" - backgroundColor={props.highlighted ? 'washedBlue' : 'white'} + backgroundColor={highlighted ? 'washedBlue' : 'white'} transcluded={0} api={api} post={post} From cb6b4e14e0050fec08fa9074b26acc1f93250da7 Mon Sep 17 00:00:00 2001 From: James Acklin Date: Sun, 25 Apr 2021 23:00:06 -0400 Subject: [PATCH 38/42] chat: stateful send button in ChatInput --- .../views/apps/chat/components/ChatInput.tsx | 50 ++++++++++++++----- .../views/apps/chat/components/chat-editor.js | 8 +++ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx index 2ad4cab26..a4d333340 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx @@ -9,9 +9,10 @@ import GlobalApi from '~/logic/api/global'; import { Envelope } from '~/types/chat-update'; import { StorageState } from '~/types'; import { Contacts, Content } from '@urbit/api'; -import { Row, BaseImage, Box, Icon, LoadingSpinner, Text } from '@tlon/indigo-react'; +import { Row, BaseImage, Box, Icon, LoadingSpinner } from '@tlon/indigo-react'; import withStorage from '~/views/components/withStorage'; import { withLocalState } from '~/logic/state/local'; +import { MOBILE_BROWSER_REGEX } from "~/logic/lib/util"; type ChatInputProps = IuseStorage & { api: GlobalApi; @@ -30,6 +31,7 @@ interface ChatInputState { inCodeMode: boolean; submitFocus: boolean; uploadingPaste: boolean; + currentInput: string; } class ChatInput extends Component { @@ -41,7 +43,8 @@ class ChatInput extends Component { this.state = { inCodeMode: false, submitFocus: false, - uploadingPaste: false + uploadingPaste: false, + currentInput: props.message, }; this.chatEditor = React.createRef(); @@ -50,6 +53,7 @@ class ChatInput extends Component { this.toggleCode = this.toggleCode.bind(this); this.uploadSuccess = this.uploadSuccess.bind(this); this.uploadError = this.uploadError.bind(this); + this.eventHandler = this.eventHandler.bind(this); } toggleCode() { @@ -61,6 +65,7 @@ class ChatInput extends Component { submit(text) { const { props, state } = this; const [, , ship, name] = props.station.split('/'); + this.setState({ currentInput: '' }); if (state.inCodeMode) { this.setState( { @@ -119,6 +124,14 @@ class ChatInput extends Component { .catch(this.uploadError); }); } + + toggleFocus(value) { + this.setState({ submitFocus: value }); + } + + eventHandler(value) { + this.setState({ currentInput: value }); + } render() { const { props, state } = this; @@ -180,6 +193,9 @@ class ChatInput extends Component { onUnmount={props.onUnmount} message={props.message} onPaste={this.onPaste.bind(this)} + focusEvent={() => this.toggleFocus(true)} + blurEvent={() => this.toggleFocus(false)} + changeEvent={this.eventHandler} placeholder='Message...' /> @@ -207,16 +223,26 @@ class ChatInput extends Component { ) ) : null} - - console.log(this.chatEditor.current.submit())} - > - Send - - + {(MOBILE_BROWSER_REGEX.test(navigator.userAgent) && + state.submitFocus) || + state.currentInput !== "" ? ( + this.chatEditor.current.submit()} + > + + + ) : null} ); } diff --git a/pkg/interface/src/views/apps/chat/components/chat-editor.js b/pkg/interface/src/views/apps/chat/components/chat-editor.js index 02fb7c6e9..fb64ef0b5 100644 --- a/pkg/interface/src/views/apps/chat/components/chat-editor.js +++ b/pkg/interface/src/views/apps/chat/components/chat-editor.js @@ -162,6 +162,7 @@ export default class ChatEditor extends Component { editor.showHint(['test', 'foo']); } if (this.state.message !== '' && value == '') { + this.props.changeEvent(value); this.setState({ message: value }); @@ -169,6 +170,7 @@ export default class ChatEditor extends Component { if (value == this.props.message || value == '' || value == ' ') { return; } + this.props.changeEvent(value); this.setState({ message: value }); @@ -179,6 +181,8 @@ export default class ChatEditor extends Component { inCodeMode, placeholder, message, + focusEvent, + blurEvent, ...props } = this.props; @@ -238,6 +242,8 @@ export default class ChatEditor extends Component { rows="1" style={{ width: '100%', background: 'transparent', color: 'currentColor' }} placeholder={inCodeMode ? "Code..." : "Message..."} + onFocus={focusEvent} + onBlur={blurEvent} onChange={event => { this.messageChange(null, null, event.target.value); }} @@ -265,6 +271,8 @@ export default class ChatEditor extends Component { this.editor = editor; editor.focus(); }} + onFocus={focusEvent} + onBlur={blurEvent} {...props} /> } From b8c495c563af4dbf99ba932e8a7bbcd9af3890f1 Mon Sep 17 00:00:00 2001 From: James Acklin Date: Mon, 26 Apr 2021 14:33:12 -0400 Subject: [PATCH 39/42] chat: no shrinking avatar in ChatInput --- pkg/interface/src/views/apps/chat/components/ChatInput.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx index a4d333340..353ce44ab 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx @@ -143,6 +143,7 @@ class ChatInput extends Component { const avatar = props.ourContact && props.ourContact?.avatar && !props.hideAvatars ? ( { className='cf' zIndex={0} > - + {avatar} Date: Mon, 26 Apr 2021 15:49:02 -0400 Subject: [PATCH 40/42] chat: persist submit button --- .../views/apps/chat/components/ChatInput.tsx | 18 +++++------------- .../views/apps/chat/components/chat-editor.js | 6 ------ 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx index 353ce44ab..403ef6427 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx @@ -44,7 +44,7 @@ class ChatInput extends Component { inCodeMode: false, submitFocus: false, uploadingPaste: false, - currentInput: props.message, + currentInput: props.message }; this.chatEditor = React.createRef(); @@ -124,10 +124,6 @@ class ChatInput extends Component { .catch(this.uploadError); }); } - - toggleFocus(value) { - this.setState({ submitFocus: value }); - } eventHandler(value) { this.setState({ currentInput: value }); @@ -194,8 +190,6 @@ class ChatInput extends Component { onUnmount={props.onUnmount} message={props.message} onPaste={this.onPaste.bind(this)} - focusEvent={() => this.toggleFocus(true)} - blurEvent={() => this.toggleFocus(false)} changeEvent={this.eventHandler} placeholder='Message...' /> @@ -224,9 +218,7 @@ class ChatInput extends Component { ) ) : null} - {(MOBILE_BROWSER_REGEX.test(navigator.userAgent) && - state.submitFocus) || - state.currentInput !== "" ? ( + {MOBILE_BROWSER_REGEX.test(navigator.userAgent) ? { width="24px" height="24px" borderRadius="50%" - backgroundColor={state.currentInput !== "" ? "blue" : "gray"} - cursor={state.currentInput !== "" ? "pointer" : "default"} + backgroundColor={state.currentInput !== '' ? 'blue' : 'gray'} + cursor={state.currentInput !== '' ? 'pointer' : 'default'} onClick={() => this.chatEditor.current.submit()} > - ) : null} + : null} ); } diff --git a/pkg/interface/src/views/apps/chat/components/chat-editor.js b/pkg/interface/src/views/apps/chat/components/chat-editor.js index fb64ef0b5..3fbf94226 100644 --- a/pkg/interface/src/views/apps/chat/components/chat-editor.js +++ b/pkg/interface/src/views/apps/chat/components/chat-editor.js @@ -181,8 +181,6 @@ export default class ChatEditor extends Component { inCodeMode, placeholder, message, - focusEvent, - blurEvent, ...props } = this.props; @@ -242,8 +240,6 @@ export default class ChatEditor extends Component { rows="1" style={{ width: '100%', background: 'transparent', color: 'currentColor' }} placeholder={inCodeMode ? "Code..." : "Message..."} - onFocus={focusEvent} - onBlur={blurEvent} onChange={event => { this.messageChange(null, null, event.target.value); }} @@ -271,8 +267,6 @@ export default class ChatEditor extends Component { this.editor = editor; editor.focus(); }} - onFocus={focusEvent} - onBlur={blurEvent} {...props} /> } From 94ad4ec3acb658bb2771ffa69f784be23d11c62f Mon Sep 17 00:00:00 2001 From: pilfer-pandex <47340789+pilfer-pandex@users.noreply.github.com> Date: Mon, 26 Apr 2021 18:58:14 -0400 Subject: [PATCH 41/42] king: fix typo in UDP.hs comment --- pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs b/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs index 8a740d7bd..018930632 100644 --- a/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs +++ b/pkg/hs/urbit-king/lib/Urbit/Vere/Ames/UDP.hs @@ -4,7 +4,7 @@ 1. Opens a UDP socket and makes sure that it stays open. - If can't open the port, wait and try again repeatedly. - - If there is an error reading or writting from the open socket, + - If there is an error reading to or writing from the open socket, close it and open another, making sure, however, to reuse the same port NOTE: It's not clear what, if anything, closing and reopening From db87197479a7329edd44031a82003d2cb010c2bd Mon Sep 17 00:00:00 2001 From: pilfer-pandex <47340789+pilfer-pandex@users.noreply.github.com> Date: Mon, 26 Apr 2021 19:22:21 -0400 Subject: [PATCH 42/42] urbit: bump version to 1.4 --- pkg/hs/urbit-king/package.yaml | 2 +- pkg/urbit/version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/hs/urbit-king/package.yaml b/pkg/hs/urbit-king/package.yaml index 03356da07..709ed1b9f 100644 --- a/pkg/hs/urbit-king/package.yaml +++ b/pkg/hs/urbit-king/package.yaml @@ -1,5 +1,5 @@ name: urbit-king -version: 1.3 +version: 1.4 license: MIT license-file: LICENSE data-files: diff --git a/pkg/urbit/version b/pkg/urbit/version index a58941b07..840ca8cbf 100644 --- a/pkg/urbit/version +++ b/pkg/urbit/version @@ -1 +1 @@ -1.3 \ No newline at end of file +1.4 \ No newline at end of file