ipfsの利用

### ローカル環境でのipfs
$ echo “version 1 of my text” > mytextfile.txt
$ cat mytextfile.txt
version 1 of my text
$ ipfs cat QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy
version 1 of my text

これをipfsネットワークで実行したい

### ipfsに接続
# ipfs daemon
別のターミナルで以下を実行
# ipfs swarm peers |head
/ip4/103.253.72.2/tcp/4001/p2p/12D3KooWMGNgfvPVhUdzWfGifHMkVvJ991EQCCEWXTREc8CPHui7
/ip4/104.244.76.218/tcp/4001/p2p/12D3KooWMbUuHSEvy4KNnkW8H9m63zesuuvVNS25hTL1SQtRh835
/ip4/109.123.240.146/tcp/4001/p2p/12D3KooWPzJcDSFQrBSgrdPbSAwTX5x6aWKWAoAzuEj3NBb43iKD
/ip4/109.203.194.197/tcp/56881/p2p/12D3KooWMgRnDE2oPkd72ZVb3pw4Pww9F24nVfCPj18gB1ARhUCt
/ip4/112.25.240.107/tcp/4001/p2p/12D3KooWHkTtvW6qCR9yATp6g8EC6hHRZGEiybyLQqmsRwoJ7Ac2
/ip4/113.89.245.184/tcp/15088/p2p/12D3KooWD8U6239pcaHdYqrg175DwM9EvFxLMuWo5PjzHd7bLZ15
/ip4/115.204.117.91/tcp/35129/p2p/12D3KooWGknnwvTJwjzYHpXgYU5K6fF2P9d8wtT3zBYudwnA7XmZ
/ip4/117.26.88.117/tcp/51698/p2p/QmQGeMkzJmkWum4FQwxvx6QPTvuNTsGoXBXeCxsWMrHg31
/ip4/136.243.46.54/tcp/4001/p2p/12D3KooWMahkHusnsTbMGVnCyXmKyLyifD8VnpMiH4hKNn6wqPfb
/ip4/136.244.116.199/tcp/4001/p2p/12D3KooWCXC9dBZZsA6E2jJh8SoyGCsGbFSLQtBquthoQpqjgpKp

ubuntuにipfsのインストール

$ wget https://dist.ipfs.io/go-ipfs/v0.5.0/go-ipfs_v0.5.0_linux-arm64.tar.gz
$ tar xvzf go-ipfs_v0.5.0_linux-arm64.tar.gz
$ cd go-ipfs/
$ sudo ./install.sh
Moved ./ipfs to /usr/local/bin
$ ipfs version
ipfs version 0.5.0
$ ipfs init
initializing IPFS node at /home/vagrant/.ipfs
generating 2048-bit RSA keypair…done
peer identity: QmWKa24RSJMHNZNSWiB5FuUkLQFvkM7L8ZqhmUKaUbLAJF
to get started, enter:

ipfs cat /ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/readme
$ ipfs cat /ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/readme
Hello and Welcome to IPFS!

██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗ ███████╗
██║██╔═══╝ ██╔══╝ ╚════██║
██║██║ ██║ ███████║
╚═╝╚═╝ ╚═╝ ╚══════╝

If you’re seeing this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!

——————————————————-
| Warning: |
| This is alpha software. Use at your own discretion! |
| Much is missing or lacking polish. There are bugs. |
| Not yet secure. Read the security notes for more. |
——————————————————-

Check out some of the other files in this directory:

./about
./help
./quick-start <-- usage examples ./readme <-- this file ./security-notes $ ls ~/.ipfs blocks config datastore datastore_spec keystore version

【IPFS】Merkle DAGをPythonで書く

import hashlib

class Node:
    def __init__(self, data=None, children=None):
        self.data = data
        self.children = children or []
        self.hash = self.compute_hash()

    def compute_hash(self):
        m = hashlib.sha256()
        if self.data:
            m.update(self.data.encode('utf-8'))
        for child in self.children:
            m.update(child.hash.encode('utf-8'))
        return m.hexdigest()

    def __repr__(self):
        return f"Node(hash={self.hash[:10]}, data={self.data})"

# ノードを作成
leaf1 = Node(data="block A")
leaf2 = Node(data="block B")
leaf3 = Node(data="block C")

# 同じ子を共有するノード
intermediate1 = Node(children=[leaf1, leaf2])
intermediate2 = Node(children=[leaf2, leaf3])

# DAGのルート
root = Node(children=[intermediate1, intermediate2])

# 表示
print("Merkle DAG:")
print("Root:", root)

$ python3 merkledag.py
Merkle DAG:
Root: Node(hash=b7026ffa9b, data=None)

同じハッシュを持つノードを共有
leaf2 は2つの親ノードに共有されており、DAGならでは構造となっている。IPFSやGitで使われる構造

backup and recovery approach using AWS

Durability
Use 99.999999999% durability of safe storage of data provided by Amazon S3.

Security
Use flexible access control applicable to data transfer and storage and various encryption options.

Global infrastructure
Since it can be used all over the world, will use regions that comply with organization’s compliance requirements, local laws and regulations, standards etc.

Compliance
Since AWS complies with various security standards around the world including SOC, ISO 27001, PCI DSS, etc., it is possible to easily match the backup mechanism to existing compliance standards.

Scalability
Since a storage area that automatically changes according to the size of the backup data is provided, there is no need to manage the storage capacity

Reduced TCO
By using full managed services, operation costs are reduced, leading to a reduction in the total cost of ownership(TCO) of backup storage.

Price based on metered basis
Since it is a usage fee based on the used capacity and duration, a life cycle plan is set so that only data necessary for backup and recovery plan is saved.

IOSPとは

IOPSとは、1秒当たりにディスクが処理できるI/Oアクセスの数
1回のI/O処理にかかる時間は、データ転送時間と平均アクセス時間とを足した数値となります。このI/O処理が1秒当たり何回実行できるかの数値がIOPS
しかしデータ転送時間には、ディスクから磁気ヘッドがデータを読み書きするインタフェースの転送速度や平均メディア転送速度やドライブの信号処理とデータ転送を制御するCPUの処理時間などが加算されるので、実は正しいなデータ転送時間は把握しづらい
一般的にはIOPSの数値が高ければ高いほど高性能なディスク

ディスクは,ディスク単体でディスク・キャッシュも搭載していますので、これも転送時間に影響を与える。メイン・メモリーを使ったディスク・キャッシュも重要

キャッシュとは?

キャッシュとは?
-> パソコンやスマホに一時的にウェブページのデータを保存しておいて、次に同じページを開いたときに素早く表示させる仕組み

メタデータでキャッシュされないように指定することができる。

<head>
	<meta http-equiv="Pragma" content="no-cache">
	<meta http-equiv="Cache-Control" content="no-cache">
</head>
<body>
hello
</body>

では、続いて、s3を使ってみましょう。

file sizeの取得

$filename = "img/test.jpg";
$size = filesize($filename);
echo "ファイルサイズ:".$size."byte";

拡張子をxlsxとして、excelをアップロードすると、

move_uploaded_file($_FILES["file"]["tmp_name"], "./img/test.xlsx");

excelがアップロードされる。

pptxだと上手くいかない。何故だ。。

wordは”*.docx”でいける。何故だ。
もしかして、upload_max_filesize?

やっぱりそうか。

amazon driveを自作しよう

機能としてはこんな感じか。
-ドキュメント、ビデオ、写真をアップロードできる。
-ドラック&ドロップでアップロードできる。
-ファイルサイズを表示する。
-アップロードファイルをURLで共有することができる。
-ファイルの中身をサムネイルで表示する。

URL共有、サムネイル表示あたりがわからん。

drop box, google drive, one drive, icloud

drop box

google drive

one drive

icloud

何気に、dropbox, google drive, one drive, icloud 全部使ってましたね。

ヤフーにも、Yahoo!ボックス というストレージサービスがあるらしいです。全然知りませんでした。

アマゾン drive

楽天はないみたい。。ストレージサービスつくりたいな。。

500GB 外付けHD

Buffalo ポータプルHDD
HD-PEU2

ハードディスク関連の仕事をしていた人から貰った。

クラウドあるから別にHDDいらないな。しかも、今1TBあるし。。