public inbox for nncp-devel@lists.cypherpunks.ru
Atom feed
* nncp-exec -use-tmp path
@ 2021-01-15 20:42 John Goerzen
  2021-01-15 21:18 ` Sergey Matveev
  0 siblings, 1 reply; 5+ messages in thread
From: John Goerzen @ 2021-01-15 20:42 UTC (permalink / raw)
  To: nncp-devel

Hi Sergey,

Thanks again for all the work you're doing on NNCP.

I noticed an odd behavior with nncp-exec -use-tmp; it's creating a 
temporary file in /tmp instead of the spool directory like the 
other commands (especially nncp-file -) are doing (or at least are 
documented to be doing).  This resulted in a failure since my /tmp 
filled up once.

Anyhow, poking around in the code, I think that's due to to the 
call to ioutil.TempFile in src/tx.go instead of using NewTmpFile 
(defined in tmp.go).

Thanks!

- John

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: nncp-exec -use-tmp path
  2021-01-15 20:42 nncp-exec -use-tmp path John Goerzen
@ 2021-01-15 21:18 ` Sergey Matveev
  2021-01-15 21:20   ` Sergey Matveev
  0 siblings, 1 reply; 5+ messages in thread
From: Sergey Matveev @ 2021-01-15 21:18 UTC (permalink / raw)
  To: nncp-devel

[-- Attachment #1: Type: text/plain, Size: 2155 bytes --]

Greetings!

*** John Goerzen [2021-01-15 14:42]:
>Anyhow, poking around in the code, I think that's due to to the call to
>ioutil.TempFile in src/tx.go instead of using NewTmpFile (defined in tmp.go).

Well, documentation for nncp-exec does not tell about temporary file
nothing -- that is bad, will fix it hopefully on that weekends However
the code for *that* temporary file is the same as for "nncp-file -",
which has more description about the behaviour: http://www.nncpgo.org/nncp_002dfile.html

ioutil.TempFile is a right call in that case: it creates temporary file
in TMPDIR: https://golang.org/pkg/os/#TempDir -- so you can control its
placement with TMPDIR environment variable. That temporary file has
narrow permissions and moreover it is delete immediately after creation
-- to delete it anyway after process is finished/crashed/killer/whatever.

It should not be the spool directory by default. For example one of my
spool directories located on a ZFS dataset with quota=2G and if
temporary file will be in the spool, then I can not transfer more than
1G of data, because contents of that temporary file must be copied in
the spool. But, anyway you can control its placement with $TMPDIR.

NewTmpFile differs from ioutil.TempFile only in one thing: it creates
files (and tmp/ directory) with umask-friendly 0666 (0777 for tmp/)
permissions. And NewTmpFile is aimed to be used only for really created
encrypted packets -- it is renamed after successful writing. And it has
to be in the spool, because renaming won't work if source and
destination files are on different filesystems.

So ioutil.TempFile is really for temporary files that will be deleted
after usage and nncp-file/nncp-exec are the only use cases for it.
NewTmpFile is for file that is for preparing encrypted packet:
it has to be in spool (actually noone guarantees that spool/tmp and
spool/NODE/{rx,tx} are on the same filesystem, but user will quickly
find that everything does not work :-)) and it has to be umask friendly.

-- 
Sergey Matveev (http://www.stargrave.org/)
OpenPGP: CF60 E89A 5923 1E76 E263  6422 AE1A 8109 E498 57EF

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: nncp-exec -use-tmp path
  2021-01-15 21:18 ` Sergey Matveev
@ 2021-01-15 21:20   ` Sergey Matveev
  2021-01-15 21:38     ` John Goerzen
  0 siblings, 1 reply; 5+ messages in thread
From: Sergey Matveev @ 2021-01-15 21:20 UTC (permalink / raw)
  To: nncp-devel

[-- Attachment #1: Type: text/plain, Size: 483 bytes --]

*** Sergey Matveev [2021-01-16 00:18]:
>ioutil.TempFile is a right call in that case:
>It should not be the spool directory by default.

Moreover ideally it should be on completely different pool/disk, to be
able to quickly copy data from it to the spool file, without making
read/write operations on the same disk/filesystem. But all of that is
user's decision.

-- 
Sergey Matveev (http://www.stargrave.org/)
OpenPGP: CF60 E89A 5923 1E76 E263  6422 AE1A 8109 E498 57EF

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: nncp-exec -use-tmp path
  2021-01-15 21:20   ` Sergey Matveev
@ 2021-01-15 21:38     ` John Goerzen
  2021-01-15 23:06       ` Sergey Matveev
  0 siblings, 1 reply; 5+ messages in thread
From: John Goerzen @ 2021-01-15 21:38 UTC (permalink / raw)
  To: Sergey Matveev; +Cc: nncp-devel


On Fri, Jan 15 2021, Sergey Matveev wrote:

> *** Sergey Matveev [2021-01-16 00:18]:
>>ioutil.TempFile is a right call in that case:
>>It should not be the spool directory by default.
>
> Moreover ideally it should be on completely different pool/disk, 
> to be
> able to quickly copy data from it to the spool file, without 
> making
> read/write operations on the same disk/filesystem. But all of 
> that is
> user's decision.

Thank you for the explanation!  It makes sense.  I had thought 
that it should be on the same disk, to facilitate a quick rename.

Just to confirm -- everything written to /tmp is encrypted, right?

- John

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: nncp-exec -use-tmp path
  2021-01-15 21:38     ` John Goerzen
@ 2021-01-15 23:06       ` Sergey Matveev
  0 siblings, 0 replies; 5+ messages in thread
From: Sergey Matveev @ 2021-01-15 23:06 UTC (permalink / raw)
  To: nncp-devel

[-- Attachment #1: Type: text/plain, Size: 739 bytes --]

*** John Goerzen [2021-01-15 15:38]:
>I had thought that it should be on the same disk, to facilitate a quick rename.

NewTmpFile is used for what you are describing. Actually it is not for
temporary storage, but for atomic file writing/renaming.
But temporary file for nncp-exec/"nncp-file -" holds really temporary
data, used for encrypted packet preparation.

>Just to confirm -- everything written to /tmp is encrypted, right?

Everything that written to the file in $TMPDIR, if more precisely.
Yes, it is encrypted with the random ephemeral key, exactly to be able
to place it anywhere you wish without fear.

-- 
Sergey Matveev (http://www.stargrave.org/)
OpenPGP: CF60 E89A 5923 1E76 E263  6422 AE1A 8109 E498 57EF

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-15 23:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15 20:42 nncp-exec -use-tmp path John Goerzen
2021-01-15 21:18 ` Sergey Matveev
2021-01-15 21:20   ` Sergey Matveev
2021-01-15 21:38     ` John Goerzen
2021-01-15 23:06       ` Sergey Matveev