Skip to content

Commit

Permalink
feat: move to ipfs webui pkger solution
Browse files Browse the repository at this point in the history
Signed-off-by: remi <remi@berty.tech>

fix: lint

Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: remi <remi@berty.tech>

fix: make tidy

Signed-off-by: remi <remi@berty.tech>

fix: js lint

Signed-off-by: remi <remi@berty.tech>

fix: diff in protoc when building

Signed-off-by: remi <remi@berty.tech>

fix: make generate
  • Loading branch information
d4ryl00-sudo committed Jun 5, 2020
1 parent b16573b commit 354458e
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 64 deletions.
Binary file removed assets/ipfs_webui.zip
Binary file not shown.
1 change: 1 addition & 0 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions go/cmd/berty/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,10 @@ func main() {
defer node.Close()

// construct http api endpoint
if err = ipfsutil.ServeHTTPApi(ctx, node); err != nil {
return err
}
ipfsutil.ServeHTTPApi(logger, node)

// serve the embedded ipfs webui
ipfsutil.ServeHTTPWebui(logger)

if crouting != nil {
routingOut = <-crouting
Expand Down
7 changes: 4 additions & 3 deletions go/framework/bertybridge/bridge_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ func newProtocolBridge(logger *zap.Logger, config *ProtocolConfig) (*Protocol, e
}

// construct http api endpoint
if err = ipfsutil.ServeHTTPApi(ctx, node); err != nil {
return nil, errcode.TODO.Wrap(err)
}
ipfsutil.ServeHTTPApi(logger, node)

// serve the embedded ipfs webui
ipfsutil.ServeHTTPWebui(logger)

out := <-crouting
dht = out.IpfsDHT
Expand Down
8 changes: 4 additions & 4 deletions go/internal/config/berty.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var BertyDev = &BertyConfig{
DefaultAPIAddrs: []string{"/ip4/127.0.0.1/tcp/5001"},
APIConfig: config.API{
HTTPHeaders: map[string][]string{
"Access-Control-Allow-Origin": []string{"*"},
"Access-Control-Allow-Methods": []string{"POST"},
"Access-Control-Allow-Origin": {"*"},
"Access-Control-Allow-Methods": {"POST"},
},
},
}
Expand All @@ -37,8 +37,8 @@ var BertyMobile = &BertyConfig{
DefaultAPIAddrs: []string{"/ip4/127.0.0.1/tcp/5001"},
APIConfig: config.API{
HTTPHeaders: map[string][]string{
"Access-Control-Allow-Origin": []string{"*"},
"Access-Control-Allow-Methods": []string{"POST"},
"Access-Control-Allow-Origin": {"*"},
"Access-Control-Allow-Methods": {"POST"},
},
},
}
27 changes: 18 additions & 9 deletions go/internal/ipfsutil/http_api.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package ipfsutil

import (
"context"
"net/http"

"berty.tech/berty/v2/go/internal/config"
ipfswebui "berty.tech/ipfs-webui-packed"
"github.com/ipfs/go-ipfs/commands"
oldcmds "github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs/core"
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
"github.com/ipfs/go-ipfs/core/corehttp"
"go.uber.org/zap"
)

// TODO(@D4ryl00) get the actal api address from the ipfs node
var DefaultAPIAddrs = config.BertyMobile.DefaultAPIAddrs
var DefaultAPIAddrs = config.BertyMobile.DefaultAPIAddrs // TODO(@D4ryl00) get the actal api address from the ipfs node

// ServeHTTPApi collects options, creates listener, prints status message and starts serving requests
func ServeHTTPApi(ctx context.Context, node *core.IpfsNode) error {
func ServeHTTPApi(logger *zap.Logger, node *core.IpfsNode) {
// mandatory for the IPFS API server
cctx := commands.Context{
// http handler requires it
ReqLog: &oldcmds.ReqLog{},
// the node is already construt so we pass it
// the node is already construct so we pass it
ConstructNode: func() (*core.IpfsNode, error) {
return node, nil
},
Expand All @@ -34,9 +35,17 @@ func ServeHTTPApi(ctx context.Context, node *core.IpfsNode) error {
}

// start the server in a new goroutine since it is not async
go func(node *core.IpfsNode, DefaultAPIAddrs string, opts ...corehttp.ServeOption) {
corehttp.ListenAndServe(node, DefaultAPIAddrs, opts...)
go func(node *core.IpfsNode, apiAddr string, opts ...corehttp.ServeOption) {
err := corehttp.ListenAndServe(node, apiAddr, opts...)
if err != nil {
logger.Error("corehttp.ListenAndServe failed", zap.Error(err))
}
}(node, DefaultAPIAddrs[0], opts...)
}

return nil
func ServeHTTPWebui(logger *zap.Logger) {
dir := http.FileServer(ipfswebui.Dir())
go func(dir http.Handler) {
logger.Error(http.ListenAndServe(":3000", dir).Error())
}(dir)
}
2 changes: 1 addition & 1 deletion js/gen.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions js/packages/berty-app/ios/Berty.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
5F9F065C52DF4948ACD06FAF /* Fontisto.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 50A51C4D5FCF4BE3BC06B638 /* Fontisto.ttf */; };
7D9D8DCF8F1B4F8287624D95 /* Feather.ttf in Resources */ = {isa = PBXBuildFile; fileRef = ACA3FA19E16C4CE289EC144D /* Feather.ttf */; };
8191D455DF674F1A89032A0A /* OpenSans-BoldItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = BC24EE9A24B2424FB34D78EF /* OpenSans-BoldItalic.ttf */; };
8A4BF33D2487F42F004D4193 /* ipfs_webui.zip in Resources */ = {isa = PBXBuildFile; fileRef = 8A4BF33C2487F42F004D4193 /* ipfs_webui.zip */; };
8A72F25B2451C4EC00CC2839 /* MultipeerConnectivity.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A72F25A2451C4EC00CC2839 /* MultipeerConnectivity.framework */; };
8A72F25C2451C4F500CC2839 /* MultipeerConnectivity.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A72F25A2451C4EC00CC2839 /* MultipeerConnectivity.framework */; };
8A72F25D2451C4FD00CC2839 /* MultipeerConnectivity.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A72F25A2451C4EC00CC2839 /* MultipeerConnectivity.framework */; };
Expand Down Expand Up @@ -93,7 +92,6 @@
691A909A3E3647AE8DE10380 /* Entypo.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Entypo.ttf; path = "../../../node_modules/react-native-vector-icons/Fonts/Entypo.ttf"; sourceTree = "<group>"; };
6A2CBB8C091C10654628B2CE /* libPods-BertyTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BertyTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
6F84C76F030A6EDBA22AB150 /* Pods-BertyTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BertyTests.debug.xcconfig"; path = "Target Support Files/Pods-BertyTests/Pods-BertyTests.debug.xcconfig"; sourceTree = "<group>"; };
8A4BF33C2487F42F004D4193 /* ipfs_webui.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; name = ipfs_webui.zip; path = ../../../../assets/ipfs_webui.zip; sourceTree = "<group>"; };
8A72F25A2451C4EC00CC2839 /* MultipeerConnectivity.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MultipeerConnectivity.framework; path = System/Library/Frameworks/MultipeerConnectivity.framework; sourceTree = SDKROOT; };
8BF04205A0A80BA5C404077E /* Pods-BertyTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BertyTests.release.xcconfig"; path = "Target Support Files/Pods-BertyTests/Pods-BertyTests.release.xcconfig"; sourceTree = "<group>"; };
8F4D2FAD70964BD9A3DC9697 /* OpenSans-SemiBold.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "OpenSans-SemiBold.ttf"; path = "../assets/OpenSans-SemiBold.ttf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -259,7 +257,6 @@
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
8A4BF33C2487F42F004D4193 /* ipfs_webui.zip */,
F8BF4661238444080077A846 /* Release.xcconfig */,
F81E8EE62382FE27007CDBA3 /* Debug.xcconfig */,
13B07FAE1A68108700A75B9A /* Berty */,
Expand Down Expand Up @@ -502,7 +499,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8A4BF33D2487F42F004D4193 /* ipfs_webui.zip in Resources */,
F8BF46862384443D0077A846 /* Images.xcassets in Resources */,
F8BF46872384443D0077A846 /* LaunchScreen.xib in Resources */,
);
Expand Down
6 changes: 1 addition & 5 deletions js/packages/berty-app/ios/Podfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions js/packages/components/settings/IpfsWebUI.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { Component } from 'react';
import { } from 'react-native';
import { View, ScrollView, StyleSheet, Text} from 'react-native'
import React, { Component } from 'react'
import { View, ScrollView, StyleSheet, Text } from 'react-native'
import { Layout } from 'react-native-ui-kitten'
import { HeaderSettings } from '../shared-components/Header'
import { WebView } from 'react-native-webview';
import { WebView } from 'react-native-webview'
import { useStyles } from '@berty-tech/styles'
import { ScreenProps, useNavigation } from '@berty-tech/berty-navigation'

Expand All @@ -27,11 +26,9 @@ const BodyIpfsWebUI: React.FC<{}> = () => {
return (
<View style={[padding.medium, flex.tiny, margin.bottom.small]}>
<WebView
//source={{ uri: 'https://webui.ipfs.io/' }}
source={{ uri: 'http://127.0.0.1:5001/webui' }}
//source={{ uri: 'http://127.0.0.1:5001/api/v0/swarm/peers', method: 'POST' }}
source={{ uri: 'http://127.0.0.1:3000' }}
//TODO: remove fixed height
style={[{height: 1000}]}
style={[{ height: 1000 }]}
/>
</View>
)
Expand All @@ -43,8 +40,7 @@ export const IpfsWebUI: React.FC<ScreenProps.Settings.IpfsWebUI> = () => {
return (
<Layout style={[background.white, flex.tiny]}>
<ScrollView contentContainerStyle={padding.bottom.scale(90)}>
<HeaderSettings title='Ipfs WebUI' bgColor={color.dark.grey} undo={goBack}>
</HeaderSettings>
<HeaderSettings title='Ipfs WebUI' bgColor={color.dark.grey} undo={goBack}></HeaderSettings>
<BodyIpfsWebUI />
</ScrollView>
</Layout>
Expand Down
10 changes: 0 additions & 10 deletions js/packages/components/settings/Network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ const HeaderNetwork: React.FC<{}> = () => {
)
}

const BodyNetwork: React.FC<{}> = () => {
const _styles = useStylesNetwork()
const [{ padding, flex, margin, color, text }] = useStyles()
return (
<View style={[padding.medium, flex.tiny, margin.bottom.small]}>
</View>
)
}

export const Network: React.FC<ScreenProps.Settings.Network> = () => {
const { goBack } = useNavigation()
const [{ background, flex, color, padding }] = useStyles()
Expand All @@ -62,7 +53,6 @@ export const Network: React.FC<ScreenProps.Settings.Network> = () => {
<HeaderSettings title='Network' bgColor={color.dark.grey} undo={goBack}>
<HeaderNetwork />
</HeaderSettings>
<BodyNetwork />
</ScrollView>
</Layout>
)
Expand Down
1 change: 0 additions & 1 deletion js/packages/go-bridge/go-bridge.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ Pod::Spec.new do |s|

s.ios.vendored_frameworks = 'ios/Frameworks/Bertybridge.framework'
s.dependency "React"
s.dependency 'ZIPFoundation'
# s.dependency "..."
end
14 changes: 0 additions & 14 deletions js/packages/go-bridge/ios/GoBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation
import Bertybridge
import ZIPFoundation

@objc(GoBridge)
class GoBridge: NSObject {
Expand Down Expand Up @@ -98,19 +97,6 @@ class GoBridge: NSObject {
NSLog("root dir: `%@`", self.rootdir.path)
config.rootDirectory(self.rootdir.path)
}

// extract the ipfs webui blocks
let ipfsWebuiPath = Bundle.main.path(forResource: "ipfs_webui", ofType: "zip")
var sourceURL = URL(fileURLWithPath: ipfsWebuiPath!)
var destinationURL = URL(fileURLWithPath: self.rootdir.path)
destinationURL.appendPathComponent("ipfs")
NSLog("Unzip destination %@", destinationURL.absoluteString)
do {
try FileManager.default.createDirectory(at: destinationURL, withIntermediateDirectories: true, attributes: nil)
try FileManager.default.unzipItem(at: sourceURL, to: destinationURL)
} catch {
print("Extraction of ZIP archive failed with error:\(error)")
}

if optTracing {
config.enableTracing()
Expand Down

0 comments on commit 354458e

Please sign in to comment.