aboutsummaryrefslogtreecommitdiffstats
path: root/modules/mail/e-mail-shell-settings.c
blob: 1434951b81ba60bb33ba6ce6b9a144ecad4e52a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
 * e-mail-shell-settings.c
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#include "e-mail-shell-settings.h"

#include <gconf/gconf-client.h>
#include <libedataserver/e-account-list.h>

#include "e-util/e-signature-list.h"
#include "mail/e-mail-label-list-store.h"
#include "mail/mail-session.h"

void
e_mail_shell_settings_init (EShell *shell)
{
    EShellSettings *shell_settings;
    gpointer object;

    shell_settings = e_shell_get_shell_settings (shell);

    /*** Global Objects ***/

    e_shell_settings_install_property (
        g_param_spec_object (
            "mail-label-list-store",
            NULL,
            NULL,
            E_TYPE_MAIL_LABEL_LIST_STORE,
            G_PARAM_READWRITE));

    object = e_mail_label_list_store_new ();
    e_shell_settings_set_object (
        shell_settings, "mail-label-list-store", object);
    g_object_unref (object);

    e_shell_settings_install_property (
        g_param_spec_pointer (
            "mail-session",
            NULL,
            NULL,
            G_PARAM_READWRITE));

    camel_object_ref (session);
    e_shell_settings_set_pointer (
        shell_settings, "mail-session", session);

    /*** Mail Preferences ***/

    e_shell_settings_install_property_for_key (
        "mail-address-compress",
        "/apps/evolution/mail/display/address_compress");

    e_shell_settings_install_property_for_key (
        "mail-address-count",
        "/apps/evolution/mail/display/address_count");

    e_shell_settings_install_property_for_key (
        "mail-charset",
        "/apps/evolution/mail/display/charset");

    e_shell_settings_install_property_for_key (
        "mail-check-for-junk",
        "/apps/evolution/mail/junk/check_incoming");

    e_shell_settings_install_property_for_key (
        "mail-citation-color",
        "/apps/evolution/mail/display/citation_colour");

    e_shell_settings_install_property_for_key (
        "mail-confirm-expunge",
        "/apps/evolution/mail/prompts/expunge");

    e_shell_settings_install_property_for_key (
        "mail-confirm-unwanted-html",
        "/apps/evolution/mail/prompts/unwanted_html");

    e_shell_settings_install_property_for_key (
        "mail-empty-junk-on-exit",
        "/apps/evolution/mail/junk/empty_on_exit");

    e_shell_settings_install_property_for_key (
        "mail-empty-trash-on-exit",
        "/apps/evolution/mail/trash/empty_on_exit");

    e_shell_settings_install_property_for_key (
        "mail-enable-search-folders",
        "/apps/evolution/mail/display/enable_vfolders");

    e_shell_settings_install_property_for_key (
        "mail-font-monospace",
        "/apps/evolution/mail/display/fonts/monospace");

    e_shell_settings_install_property_for_key (
        "mail-font-variable",
        "/apps/evolution/mail/display/fonts/variable");

    e_shell_settings_install_property_for_key (
        "mail-force-message-limit",
        "/apps/evolution/mail/display/force_message_limit");

    /* This value corresponds to MailConfigForwardStyle enum. */
    e_shell_settings_install_property_for_key (
        "mail-forward-style",
        "/apps/evolution/mail/format/forward_style");

    /* This value corresponds to MailConfigHTTPMode enum. */
    e_shell_settings_install_property_for_key (
        "mail-image-loading-policy",
        "/apps/evolution/mail/display/load_http_images");

    e_shell_settings_install_property_for_key (
        "mail-magic-spacebar",
        "/apps/evolution/mail/display/magic_spacebar");

    e_shell_settings_install_property_for_key (
        "mail-mark-citations",
        "/apps/evolution/mail/display/mark_citations");

    e_shell_settings_install_property_for_key (
        "mail-mark-seen",
        "/apps/evolution/mail/display/mark_seen");

    e_shell_settings_install_property_for_key (
        "mail-mark-seen-timeout",
        "/apps/evolution/mail/display/mark_seen_timeout");

    e_shell_settings_install_property_for_key (
        "mail-message-text-part-limit",
        "/apps/evolution/mail/display/message_text_part_limit");

    e_shell_settings_install_property_for_key (
        "mail-only-local-photos",
        "/apps/evolution/mail/display/photo_local");

    e_shell_settings_install_property_for_key (
        "mail-show-real-date",
        "/apps/evolution/mail/display/show_real_date");

    e_shell_settings_install_property_for_key (
        "mail-prompt-delete-in-vfolder",
        "/apps/evolution/mail/prompts/delete_in_vfolder");

    /* This value corresponds to MailConfigReplyStyle enum,
     * but the ordering of the combo box items in preferences
     * has changed.  We use transformation functions there. */
    e_shell_settings_install_property_for_key (
        "mail-reply-style",
        "/apps/evolution/mail/format/reply_style");

    e_shell_settings_install_property_for_key (
        "mail-show-animated-images",
        "/apps/evolution/mail/display/animated_images");

    e_shell_settings_install_property_for_key (
        "mail-show-sender-photo",
        "/apps/evolution/mail/display/sender_photo");

    e_shell_settings_install_property_for_key (
        "mail-side-bar-search",
        "/apps/evolution/mail/display/side_bar_search");

    e_shell_settings_install_property_for_key (
        "mail-use-custom-fonts",
        "/apps/evolution/mail/display/fonts/use_custom");

    /*** Composer Preferences ***/

    e_shell_settings_install_property_for_key (
        "composer-charset",
        "/apps/evolution/mail/composer/charset");

    e_shell_settings_install_property_for_key (
        "composer-format-html",
        "/apps/evolution/mail/composer/send_html");

    e_shell_settings_install_property_for_key (
        "composer-inline-spelling",
        "/apps/evolution/mail/composer/inline_spelling");

    e_shell_settings_install_property_for_key (
        "composer-magic-links",
        "/apps/evolution/mail/composer/magic_links");

    e_shell_settings_install_property_for_key (
        "composer-magic-smileys",
        "/apps/evolution/mail/composer/magic_smileys");

    e_shell_settings_install_property_for_key (
        "composer-outlook-filenames",
        "/apps/evolution/mail/composer/outlook_filenames");

    e_shell_settings_install_property_for_key (
        "composer-prompt-only-bcc",
        "/apps/evolution/mail/prompts/only_bcc");

    e_shell_settings_install_property_for_key (
        "composer-prompt-empty-subject",
        "/apps/evolution/mail/prompts/empty_subject");

    e_shell_settings_install_property_for_key (
        "composer-reply-start-bottom",
        "/apps/evolution/mail/composer/reply_start_bottom");

    e_shell_settings_install_property_for_key (
        "composer-request-receipt",
        "/apps/evolution/mail/composer/request_receipt");

    e_shell_settings_install_property_for_key (
        "composer-spell-color",
        "/apps/evolution/mail/composer/spell_color");

    e_shell_settings_install_property_for_key (
        "composer-top-signature",
        "/apps/evolution/mail/composer/top_signature");

    e_shell_settings_install_property_for_key (
        "composer-no-signature-delim",
        "/apps/evolution/mail/composer/no_signature_delim");
}
ithub.com/ethereum/go-ethereum
+ # use canned dependencies from the go-ethereum repository
+ - export GOPATH=$GOPATH:$GOPATH/src/github.com/ethereum/go-ethereum/Godeps/_workspace/
+ - echo $GOPATH
install:
+ # need to explicitly request version 1.48 since by default we get 1.46 which does not work with C++11
- sudo apt-get install -qq --yes --force-yes g++-4.8
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
- # need to explicitly request version 1.48 since by default we get 1.46 which does not work with C++11
- - sudo apt-get install -qq wget cmake bash libboost-test1.48-dev libboost-system1.48-dev libboost-filesystem1.48-dev nodejs python-pip python-dev
+ - sudo apt-get install -qq wget cmake bash libboost-test1.48-dev libboost-system1.48-dev libboost-filesystem1.48-dev nodejs python-pip python-dev valgrind
- sudo pip install virtualenv -q
script: "./test/test.sh"
diff --git a/Godeps/_workspace/src/github.com/ethereum/ethash/README.md b/Godeps/_workspace/src/github.com/ethereum/ethash/README.md
index 8b9e015cf..2b2c3b544 100644
--- a/Godeps/_workspace/src/github.com/ethereum/ethash/README.md
+++ b/Godeps/_workspace/src/github.com/ethereum/ethash/README.md
@@ -1,7 +1,22 @@
[![Build Status](https://travis-ci.org/ethereum/ethash.svg?branch=master)](https://travis-ci.org/ethereum/ethash)
-
+[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/debris/ethash?branch=master&svg=true)](https://ci.appveyor.com/project/debris/ethash-nr37r/branch/master)
# Ethash
For details on this project, please see the Ethereum wiki:
https://github.com/ethereum/wiki/wiki/Ethash
+
+### Coding Style for C++ code:
+
+Follow the same exact style as in [cpp-ethereum](https://github.com/ethereum/cpp-ethereum/blob/develop/CodingStandards.txt)
+
+### Coding Style for C code:
+
+The main thing above all is code consistency.
+
+- Tabs for indentation. A tab is 4 spaces
+- Try to stick to the [K&R](http://en.wikipedia.org/wiki/Indent_style#K.26R_style),
+ especially for the C code.
+- Keep the line lengths reasonable. No hard limit on 80 characters but don't go further
+ than 110. Some people work with multiple buffers next to each other.
+ Make them like you :)
diff --git a/Godeps/_workspace/src/github.com/ethereum/ethash/appveyor.yml b/Godeps/_workspace/src/github.com/ethereum/ethash/appveyor.yml
new file mode 100644
index 000000000..ac36a0626
--- /dev/null
+++ b/Godeps/_workspace/src/github.com/ethereum/ethash/appveyor.yml
@@ -0,0 +1,43 @@
+version: 1.0.0.{build}
+
+environment:
+ BOOST_ROOT: "c:/projects/ethash/deps/boost"
+
+branches:
+ only:
+ - master
+ - develop
+
+os: Windows Server 2012 R2
+
+clone_folder: c:\projects\ethash
+
+#platform: Any CPU
+#configuration: Debug
+
+install:
+ # by default, all script lines are interpreted as batch
+
+# scripts to run before build
+before_build:
+ - echo "Downloading boost..."
+ - mkdir c:\projects\ethash\deps
+ - cd c:\projects\ethash\deps
+ - curl -O https://build.ethdev.com/builds/windows-precompiled/boost.tar.gz
+ - echo "Unzipping boost..."
+ - 7z x boost.tar.gz > nul
+ - 7z x boost.tar > nul
+ - ls
+ - echo "Running cmake..."
+ - cd c:\projects\ethash
+ - cmake .
+
+build:
+ project: ALL_BUILD.vcxproj # path to Visual Studio solution or project
+
+after_build:
+ - echo "Running tests..."
+ - cd c:\projects\ethash\test\c\Debug
+ - Test.exe
+ - echo "Finished!"
+
diff --git a/Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go b/Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
index 74285a33c..1ee980765 100644
--- a/Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
+++ b/Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
@@ -1,32 +1,22 @@
-/*
-###################################################################################
-###################################################################################
-#################### ####################
-#################### EDIT AND YOU SHALL FEEL MY WRATH - jeff ####################
-#################### ####################
-###################################################################################
-###################################################################################
-*/
-
package ethash
/*
-#cgo CFLAGS: -std=gnu99 -Wall
-#include "src/libethash/util.c"
-#include "src/libethash/internal.c"
-#include "src/libethash/sha3.c"
+#include "src/libethash/internal.h"
+
+int ethashGoCallback_cgo(unsigned);
*/
import "C"
import (
- "bytes"
- "encoding/binary"
+ "errors"
"fmt"
"io/ioutil"
"math/big"
"math/rand"
"os"
- "path"
+ "os/user"
+ "path/filepath"
+ "runtime"
"sync"
"time"
"unsafe"
@@ -38,318 +28,267 @@ import (
"github.com/ethereum/go-ethereum/pow"
)
-var minDifficulty = new(big.Int).Exp(big.NewInt(2), big.NewInt(256), big.NewInt(0))
-
-type ParamsAndCache struct {
- params *C.ethash_params
- cache *C.ethash_cache
- Epoch uint64
-}
-
-type DAG struct {
- dag unsafe.Pointer // full GB of memory for dag
- file bool
- paramsAndCache *ParamsAndCache
-}
-
-type Ethash struct {
- turbo bool
- HashRate int64
- chainManager pow.ChainManager
- dag *DAG
- paramsAndCache *ParamsAndCache
- ret *C.ethash_return_value
- dagMutex *sync.RWMutex
- cacheMutex *sync.RWMutex
-}
+var (
+ minDifficulty = new(big.Int).Exp(big.NewInt(2), big.NewInt(256), big.NewInt(0))
+ sharedLight = new(Light)
+)
-func parseNonce(nonce []byte) (uint64, error) {
- nonceBuf := bytes.NewBuffer(nonce)
- nonceInt, err := binary.ReadUvarint(nonceBuf)
- if err != nil {
- return 0, err
- }
- return nonceInt, nil
-}
+const (
+ epochLength uint64 = 30000
+ cacheSizeForTesting C.uint64_t = 1024
+ dagSizeForTesting C.uint64_t = 1024 * 32
+)
-const epochLength uint64 = 30000
+var DefaultDir = defaultDir()
-func makeParamsAndCache(chainManager pow.ChainManager, blockNum uint64) (*ParamsAndCache, error) {
- if blockNum >= epochLength*2048 {
- return nil, fmt.Errorf("block number is out of bounds (value %v, limit is %v)", blockNum, epochLength*2048)
+func defaultDir() string {
+ home := os.Getenv("HOME")
+ if user, err := user.Current(); err == nil {
+ home = user.HomeDir
}
- paramsAndCache := &ParamsAndCache{
- params: new(C.ethash_params),
- cache: new(C.ethash_cache),
- Epoch: blockNum / epochLength,
+ if runtime.GOOS == "windows" {
+ return filepath.Join(home, "AppData", "Ethash")
}
- C.ethash_params_init(paramsAndCache.params, C.uint32_t(uint32(blockNum)))
- paramsAndCache.cache.mem = C.malloc(C.size_t(paramsAndCache.params.cache_size))
-
- seedHash, err := GetSeedHash(blockNum)
- if err != nil {
- return nil, err
- }
-
- glog.V(logger.Info).Infof("Making cache for epoch: %d (%v) (%x)\n", paramsAndCache.Epoch, blockNum, seedHash)
- start := time.Now()
- C.ethash_mkcache(paramsAndCache.cache, paramsAndCache.params, (*C.ethash_blockhash_t)(unsafe.Pointer(&seedHash[0])))
+ return filepath.Join(home, ".ethash")
+}
- if glog.V(logger.Info) {
- glog.Infoln("Took:", time.Since(start))
- }
+// cache wraps an ethash_light_t with some metadata
+// and automatic memory management.
+type cache struct {
+ epoch uint64
+ test bool
- return paramsAndCache, nil
+ gen sync.Once // ensures cache is only generated once.
+ ptr *C.struct_ethash_light
}
-func (pow *Ethash) UpdateCache(blockNum uint64, force bool) error {
- pow.cacheMutex.Lock()
- defer pow.cacheMutex.Unlock()
-
- thisEpoch := blockNum / epochLength
- if force || pow.paramsAndCache.Epoch != thisEpoch {
- var err error
- pow.paramsAndCache, err = makeParamsAndCache(pow.chainManager, blockNum)
- if err != nil {
- panic(err)
+// generate creates the actual cache. it can be called from multiple
+// goroutines. the first call will generate the cache, subsequent
+// calls wait until it is generated.
+func (cache *cache) generate() {
+ cache.gen.Do(func() {
+ started := time.Now()
+ seedHash := makeSeedHash(cache.epoch)
+ glog.V(logger.Debug).Infof("Generating cache for epoch %d (%x)", cache.epoch, seedHash)
+ size := C.ethash_get_cachesize(C.uint64_t(cache.epoch * epochLength))
+ if cache.test {
+ size = cacheSizeForTesting
}
- }
-
- return nil
+ cache.ptr = C.ethash_light_new_internal(size, (*C.ethash_h256_t)(unsafe.Pointer(&seedHash[0])))
+ runtime.SetFinalizer(cache, freeCache)
+ glog.V(logger.Debug).Infof("Done generating cache for epoch %d, it took %v", cache.epoch, time.Since(started))
+ })
}
-func makeDAG(p *ParamsAndCache) *DAG {
- d := &DAG{
- dag: C.malloc(C.size_t(p.params.full_size)),
- file: false,
- paramsAndCache: p,
- }
+func freeCache(cache *cache) {
+ C.ethash_light_delete(cache.ptr)
+ cache.ptr = nil
+}
- donech := make(chan string)
- go func() {
- t := time.NewTicker(5 * time.Second)
- tstart := time.Now()
- done:
- for {
- select {
- case <-t.C:
- glog.V(logger.Info).Infof("... still generating DAG (%v) ...\n", time.Since(tstart).Seconds())
- case str := <-donech:
- glog.V(logger.Info).Infof("... %s ...\n", str)
- break done
- }
- }
- }()
- C.ethash_compute_full_data(d.dag, p.params, p.cache)
- donech <- "DAG generation completed"
- return d
+// Light implements the Verify half of the proof of work.
+// It uses a small in-memory cache to verify the nonces
+// found by Full.
+type Light struct {
+ test bool // if set use a smaller cache size
+ mu sync.Mutex // protects current
+ current *cache // last cache which was generated.
+ // TODO: keep multiple caches.
}
-func (pow *Ethash) writeDagToDisk(dag *DAG, epoch uint64) *os.File {
- if epoch > 2048 {
- panic(fmt.Errorf("Epoch must be less than 2048 (is %v)", epoch))
+// Verify checks whether the block's nonce is valid.
+func (l *Light) Verify(block pow.Block) bool {
+ // TODO: do ethash_quick_verify before getCache in order
+ // to prevent DOS attacks.
+ var (
+ blockNum = block.NumberU64()
+ difficulty = block.Difficulty()
+ cache = l.getCache(blockNum)
+ dagSize = C.ethash_get_datasize(C.uint64_t(blockNum))
+ )
+ if l.test {
+ dagSize = dagSizeForTesting
}
- data := C.GoBytes(unsafe.Pointer(dag.dag), C.int(dag.paramsAndCache.params.full_size))
- file, err := os.Create("/tmp/dag")
- if err != nil {
- panic(err)
+ if blockNum >= epochLength*2048 {
+ glog.V(logger.Debug).Infof("block number %d too high, limit is %d", epochLength*2048)
+ return false
}
+ // Recompute the hash using the cache.
+ hash := hashToH256(block.HashNoNonce())
+ ret := C.ethash_light_compute_internal(cache.ptr, dagSize, hash, C.uint64_t(block.Nonce()))
+ if !ret.success {
+ return false
+ }
+ // Make sure cache is live until after the C call.
+ // This is important because a GC might happen and execute
+ // the finalizer before the call completes.
+ _ = cache
+ // The actual check.
+ target := new(big.Int).Div(minDifficulty, difficulty)
+ return h256ToHash(ret.result).Big().Cmp(target) <= 0
+}
- dataEpoch := make([]byte, 8)
- binary.BigEndian.PutUint64(dataEpoch, epoch)
-
- file.Write(dataEpoch)
- file.Write(data)
+func h256ToHash(in C.struct_ethash_h256) common.Hash {
+ return *(*common.Hash)(unsafe.Pointer(&in.b))
+}
- return file
+func hashToH256(in common.Hash) C.struct_ethash_h256 {
+ return C.struct_ethash_h256{b: *(*[32]C.uint8_t)(unsafe.Pointer(&in[0]))}
}
-func (pow *Ethash) UpdateDAG() {
- blockNum := pow.chainManager.CurrentBlock().NumberU64()
- if blockNum >= epochLength*2048 {
- // This will crash in the 2030s or 2040s
- panic(fmt.Errorf("Current block number is out of bounds (value %v, limit is %v)", blockNum, epochLength*2048))
+func (l *Light) getCache(blockNum uint64) *cache {
+ var c *cache
+ epoch := blockNum / epochLength
+ // Update or reuse the last cache.
+ l.mu.Lock()
+ if l.current != nil && l.current.epoch == epoch {
+ c = l.current
+ } else {
+ c = &cache{epoch: epoch, test: l.test}
+ l.current = c
}
+ l.mu.Unlock()
+ // Wait for the cache to finish generating.
+ c.generate()
+ return c
+}
- pow.dagMutex.Lock()
- defer pow.dagMutex.Unlock()
- thisEpoch := blockNum / epochLength
- if pow.dag == nil || pow.dag.paramsAndCache.Epoch != thisEpoch {
- if pow.dag != nil && pow.dag.dag != nil {
- C.free(pow.dag.dag)
- pow.dag.dag = nil
- }
+// dag wraps an ethash_full_t with some metadata
+// and automatic memory management.
+type dag struct {
+ epoch uint64
+ test bool
+ dir string
- if pow.dag != nil && pow.dag.paramsAndCache.cache.mem != nil {
- C.free(pow.dag.paramsAndCache.cache.mem)
- pow.dag.paramsAndCache.cache.mem = nil
- }
+ gen sync.Once // ensures DAG is only generated once.
+ ptr *C.struct_ethash_full
+}
- // Make the params and cache for the DAG
- paramsAndCache, err := makeParamsAndCache(pow.chainManager, blockNum)
- if err != nil {
- panic(err)
+// generate creates the actual DAG. it can be called from multiple
+// goroutines. the first call will generate the DAG, subsequent
+// calls wait until it is generated.
+func (d *dag) generate() {
+ d.gen.Do(func() {
+ var (
+ started = time.Now()
+ seedHash = makeSeedHash(d.epoch)
+ blockNum = C.uint64_t(d.epoch * epochLength)
+ cacheSize = C.ethash_get_cachesize(blockNum)
+ dagSize = C.ethash_get_datasize(blockNum)
+ )
+ if d.test {
+ cacheSize = cacheSizeForTesting
+ dagSize = dagSizeForTesting
}
-
- // TODO: On non-SSD disks, loading the DAG from disk takes longer than generating it in memory
- pow.paramsAndCache = paramsAndCache
- path := path.Join("/", "tmp", "dag")
- pow.dag = nil
- glog.V(logger.Info).Infoln("Retrieving DAG")
- start := time.Now()
-
- file, err := os.Open(path)
- if err != nil {
- glog.V(logger.Info).Infof("No DAG found. Generating new DAG in '%s' (this takes a while)...\n", path)
- pow.dag = makeDAG(paramsAndCache)
- file = pow.writeDagToDisk(pow.dag, thisEpoch)
- pow.dag.file = true
- } else {
- data, err := ioutil.ReadAll(file)
- if err != nil {
- glog.V(logger.Info).Infof("DAG load err: %v\n", err)
- }
-
- if len(data) < 8 {
- glog.V(logger.Info).Infof("DAG in '%s' is less than 8 bytes, it must be corrupted. Generating new DAG (this takes a while)...\n", path)
- pow.dag = makeDAG(paramsAndCache)
- file = pow.writeDagToDisk(pow.dag, thisEpoch)
- pow.dag.file = true
- } else {
- dataEpoch := binary.BigEndian.Uint64(data[0:8])
- if dataEpoch < thisEpoch {
- glog.V(logger.Info).Infof("DAG in '%s' is stale. Generating new DAG (this takes a while)...\n", path)
- pow.dag = makeDAG(paramsAndCache)
- file = pow.writeDagToDisk(pow.dag, thisEpoch)
- pow.dag.file = true
- } else if dataEpoch > thisEpoch {
- // FIXME
- panic(fmt.Errorf("Saved DAG in '%s' reports to be from future epoch %v (current epoch is %v)\n", path, dataEpoch, thisEpoch))
- } else if len(data) != (int(paramsAndCache.params.full_size) + 8) {
- glog.V(logger.Info).Infof("DAG in '%s' is corrupted. Generating new DAG (this takes a while)...\n", path)
- pow.dag = makeDAG(paramsAndCache)
- file = pow.writeDagToDisk(pow.dag, thisEpoch)
- pow.dag.file = true
- } else {
- data = data[8:]
- pow.dag = &DAG{
- dag: unsafe.Pointer(&data[0]),
- file: true,
- paramsAndCache: paramsAndCache,
- }
- }
- }
+ if d.dir == "" {
+ d.dir = DefaultDir
}
- glog.V(logger.Info).Infoln("Took:", time.Since(start))
-
- file.Close()
- }
-}
-
-func New(chainManager pow.ChainManager) *Ethash {
- paramsAndCache, err := makeParamsAndCache(chainManager, chainManager.CurrentBlock().NumberU64())
- if err != nil {
- panic(err)
- }
-
- return &Ethash{
- turbo: true,
- paramsAndCache: paramsAndCache,